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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ jobs:
LOOP_IMPL: ${{ matrix.loop }}
SERVER_VERSION: ${{ matrix.edgedb-version }}
run: |
if [ "${SERVER_VERSION}" = "nightly" ]; then
export EDGEDB_TEST_CODEGEN_ASSERT_SUFFIX=.assert4
fi
if [ "${LOOP_IMPL}" = "uvloop" ]; then
env USE_UVLOOP=1 python -m unittest -v tests.suite
else
Expand Down
7 changes: 7 additions & 0 deletions edgedb/codegen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@

PYDANTIC_MIXIN = """\
class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import uuid


class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import uuid


class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import uuid


class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import uuid


class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import uuid


class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ MyScalar = int


class NoPydanticValidation:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type, _handler):
# Pydantic 2.x
from pydantic_core.core_schema import any_schema
return any_schema()

@classmethod
def __get_validators__(cls):
# Pydantic 1.x
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
Expand Down
3 changes: 2 additions & 1 deletion tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from edgedb import _testbase as tb


ASSERT_SUFFIX = os.environ.get("EDGEDB_TEST_CODEGEN_ASSERT_SUFFIX", ".assert")
# Use ".assert" for EdgeDB 3.x and lower
ASSERT_SUFFIX = os.environ.get("EDGEDB_TEST_CODEGEN_ASSERT_SUFFIX", ".assert4")


class TestCodegen(tb.AsyncQueryTestCase):
Expand Down
Loading