jerber / MagicDB

MIT License
3 stars 1 forks source link

Use construct() for forgiveness... and figure out more elegant way to validate from it #9

Closed jerber closed 3 years ago

jerber commented 4 years ago

you can then create a new instance of User without

re-running validation which would be unnecessary at this point:

new_user = User.construct(_fields_set=fields_set, **user_data) print(repr(new_user))

> User(name='John Doe', id=123, age=32)

print(new_user.__fields_set__)

> {'age', 'id'}

https://pydantic-docs.helpmanual.io/usage/models/#creating-models-without-validation

jerber commented 4 years ago

Maybe the default functionality of Pydantic (validates on constr) is desired. Have an arg for .get() in query that allows for forgiveness, in which case you use construct()

jerber commented 3 years ago

Done...