qiboteam / qibodb

Apache License 2.0
2 stars 0 forks source link

Validation #2

Open alecandido opened 1 year ago

alecandido commented 1 year ago

@scarrazza @stavros11 I'm now facing the problem of whom delegating the validation to.

I have essentially two ingredients, that generate two possible options:

The database has of course has to be there, but it only works with dictionaries (and at most TypedDict for type hints). However, Pydantic gives me the objects, it should be able to turn the model specified by them into a JSON schema (which I would not need any longer), and it has a better integration with type checks.

On the one side, I wonder if I should keep insisting with Pydantic adoption, since I could do everything with MongoDB (giving up on type hints, and writing manually the JSON schema). On the other, I really want the objects, rather than dictionaries around, and Pydantic is a dependency actively developed, with >13k stars on GitHub... all in all it seems quite reliable.

So, the two tools are so complete that they span part of the things done by the other, and in particular validation is in both. But they are also complementary, so I would just decide to whom attributing the intersection, and keep using both to have the full set of features.

scarrazza commented 1 year ago

The command approach requires more effort from the developer point of view in my opinion. Pydantic+MongoDB seems the standard (even mentioned in mongo's docs) when using APIs like FastAPI, so I would go for this option.

alecandido commented 1 year ago

Ok, perfect, I will go that way.

For the sake of reporting:

  1. in principle, there would have been even another option: mongoengine. It is another reliable package, implementing an ODM (essentially SQLAlchemy for Mongo). However, the object side seems less featureful than Pydantic
  2. I saw that tutorial, it's essentially this app, and another package used is Motor, an official driver for MongoDB. However, I won't use Motor, since it is only needed for async applications, and I believe there is no need for async at the moment, while it would increase the complexity