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

Fix for Pydantic 2.x #468

Merged
merged 2 commits into from
Jan 9, 2024
Merged

Fix for Pydantic 2.x #468

merged 2 commits into from
Jan 9, 2024

Conversation

fantix
Copy link
Member

@fantix fantix commented Nov 30, 2023

Background:

Solution:

Skip constructing dataclass schema under Pydantic v2 through __get_pydantic_core_schema__(), which:

  1. Avoids looking into the model types at all, unblocking FastAPI with Pydantic v2;
  2. Skips Pydantic validation;
  3. Is preferred over the __get_validators__(), so the latter can stay for v1 compatibility.

Fixes #466

@fantix
Copy link
Member Author

fantix commented Nov 30, 2023

When returning edgedb-python query results directly as a FastAPI response as demonstrated in the tutorial, the objects are inferred as dataclass by Pydantic, and serialized directly through the dict from dataclass. Both edgedb-python and Pydantic in this case are native Python extensions.

Stable server is now 4.x
Refs: 56aba5b
@jsimonlane
Copy link

Hey @fantix -- what's the status of getting this CR reviewed? Thanks!

@jsimonlane
Copy link

Bumping this one more time, any update on getting this CR approved? Guessing the above comment got lost in the Holiday scuffle. @1st1 @fantix ?

Thanks!

@fantix
Copy link
Member Author

fantix commented Jan 8, 2024

Sorry yeah, I'm hoping to get a review and put out a new release in a day or two

@fantix fantix merged commit 9fedd1d into master Jan 9, 2024
42 checks passed
@fantix fantix deleted the pydantic-v2 branch January 9, 2024 19:50
fantix added a commit that referenced this pull request Jan 9, 2024
fantix added a commit that referenced this pull request Jan 9, 2024
Fixes
=====

* Fix test that broke due to error message change (#465)
  (by @msullivan in fed7b24 for #465)

* Don't fail if 'id' is missing from an object. (#464)
  (by @msullivan in be2de71 for #464)

* docs: Fix typos is docs (#467)
  (by @elliotwaite in b4d91b9 for #467)

* Fix for Pydantic 2.x (#468)
  (by @fantix in c6581cb for #468)
@fantix fantix mentioned this pull request Jan 9, 2024
@jsimonlane
Copy link

Thanks @fantix !

@aljazerzen aljazerzen mentioned this pull request Feb 23, 2024
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

Successfully merging this pull request may close these issues.

PydanticV2 breaks EdgeDB's Python CodeGen
2 participants