Skip to content

SQLModel-subclassed constructors using unpacked string dictionaries fail with underlying pydantic 2.x #1004

Answered by brokenbek
brokenbek asked this question in Questions
Discussion options

You must be logged in to vote

In the hopes that others will benefit, I'm documenting what I believe to be the right approach for my situation. Rather than this pattern (from the code above):

d = dict(enabled='True', count='1234', gauge='56.78')
foo_2 = Foo(**d)

...this pattern achieves my aim:

d = dict(enabled='True', count='1234', gauge='56.78')
foo_2 = Foo.model_validate(d)

It's only a little more verbose, and the updates to my codebase, while not small in number, are nicely surgical.

Happy coding!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@brokenbek
Comment options

Answer selected by brokenbek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
1 participant