From c6581cbddd8f64f4bda7053edfbd55e8b8307cd5 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Wed, 10 Jan 2024 04:50:28 +0900 Subject: [PATCH] Fix for Pydantic 2.x (#468) --- .github/workflows/tests.yml | 3 --- edgedb/codegen/generator.py | 7 +++++++ .../select_optional_json_async_edgeql.py.assert | 7 +++++++ .../test-project2/object/link_prop_async_edgeql.py.assert | 7 +++++++ .../object/select_object_async_edgeql.py.assert | 7 +++++++ .../object/select_objects_async_edgeql.py.assert | 7 +++++++ .../parpkg/select_args_async_edgeql.py.assert | 7 +++++++ .../parpkg/subpkg/my_query_async_edgeql.py.assert | 7 +++++++ tests/test_codegen.py | 3 ++- 9 files changed, 51 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14f735c0..5dfe6041 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/edgedb/codegen/generator.py b/edgedb/codegen/generator.py index 685c93b0..09f9bf4e 100644 --- a/edgedb/codegen/generator.py +++ b/edgedb/codegen/generator.py @@ -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: [] diff --git a/tests/codegen/test-project1/select_optional_json_async_edgeql.py.assert b/tests/codegen/test-project1/select_optional_json_async_edgeql.py.assert index 8588dd54..cdfcd972 100644 --- a/tests/codegen/test-project1/select_optional_json_async_edgeql.py.assert +++ b/tests/codegen/test-project1/select_optional_json_async_edgeql.py.assert @@ -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: [] diff --git a/tests/codegen/test-project2/object/link_prop_async_edgeql.py.assert b/tests/codegen/test-project2/object/link_prop_async_edgeql.py.assert index 2185f9c7..7bff2c40 100644 --- a/tests/codegen/test-project2/object/link_prop_async_edgeql.py.assert +++ b/tests/codegen/test-project2/object/link_prop_async_edgeql.py.assert @@ -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: [] diff --git a/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert b/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert index 70c1bae8..56d040a2 100644 --- a/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert +++ b/tests/codegen/test-project2/object/select_object_async_edgeql.py.assert @@ -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: [] diff --git a/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert b/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert index b293172a..d193082b 100644 --- a/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert +++ b/tests/codegen/test-project2/object/select_objects_async_edgeql.py.assert @@ -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: [] diff --git a/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert b/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert index 7485f3aa..10327852 100644 --- a/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert +++ b/tests/codegen/test-project2/parpkg/select_args_async_edgeql.py.assert @@ -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: [] diff --git a/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert b/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert index 147be8c1..658fdd72 100644 --- a/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert +++ b/tests/codegen/test-project2/parpkg/subpkg/my_query_async_edgeql.py.assert @@ -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: [] diff --git a/tests/test_codegen.py b/tests/test_codegen.py index f2efa585..182a1f1a 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -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):