edgedb / edgedb-python

The official Python client library for EdgeDB
https://edgedb.com
Apache License 2.0
366 stars 43 forks source link

Fix for Pydantic 2.x #468

Closed fantix closed 5 months ago

fantix commented 7 months ago

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 commented 7 months ago

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.

jsimonlane commented 6 months ago

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

jsimonlane commented 6 months ago

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 commented 6 months ago

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

jsimonlane commented 4 months ago

Thanks @fantix !