From f4125a5065f74213df36d6dfe55fddde89cd1a1c Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 30 Nov 2023 17:34:35 -0500 Subject: [PATCH 1/2] Fix for Pydantic 2.x --- 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 +++++++ 7 files changed, 49 insertions(+) diff --git a/edgedb/codegen/generator.py b/edgedb/codegen/generator.py index 6a02352e..9b657d3a 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 cd7d6bb2..d9aa5a01 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: [] From 3a740e9abbb38fbc90d9cb093fc7ae8f92f1e56c Mon Sep 17 00:00:00 2001 From: Fantix King Date: Fri, 1 Dec 2023 11:21:23 -0500 Subject: [PATCH 2/2] Fix codegen test and CI Stable server is now 4.x Refs: https://github.com/edgedb/edgedb-python/pull/461/commits/56aba5b4ed2f42eaa6a81e15a4faca9a46bd51aa --- .github/workflows/tests.yml | 3 --- tests/test_codegen.py | 3 ++- 2 files changed, 2 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/tests/test_codegen.py b/tests/test_codegen.py index 801b00ae..6b041dbd 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):