PydanticModel class
#1334
dantownsend
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently we have good Pydantic support, via the
create_pydantic_modelfunction (see docs). For example:We could potentially add a
PydanticModelclass, which performs something similar (it will likely usecreate_pydantic_modelunder the hood):It would require some metaclass magic to make this work.
The advantages over
create_pydantic_modelare:It's easier to add additional fields to the model
With
create_pydantic_model:With
PydanticModel:Less likely a name clash will occur
With
create_pydantic_model, if it's used multiple times on the same table, it's important to provide themodel_nameargument, to prevent issues with FastAPI:With
PydanticModel, this problem is avoided, as the model name is automatically just the class name.Update 24/3/2022
If building a new API around Pydantic model creation, these are the other things I'd change from the current
create_pydantic_modelimplementation:include_default_columnsoption, as it's redundant nowinclude_columnsandexclude_columnsexist.Beta Was this translation helpful? Give feedback.
All reactions