Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation #2

Open
alecandido opened this issue May 29, 2023 · 2 comments
Open

Validation #2

alecandido opened this issue May 29, 2023 · 2 comments

Comments

@alecandido
Copy link
Member

alecandido commented May 29, 2023

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

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

  • MongoDB: by default it has no validation, but I can set it with a command passing a JSON schema
  • Pydantic, that is made on purpose, and it will turn dictionaries in objects

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
Copy link
Member

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants