From 1569764c07809ca7e18f3a785eaea775a6946319 Mon Sep 17 00:00:00 2001 From: Rami Chowdhury Date: Mon, 9 Dec 2024 23:36:09 -0500 Subject: [PATCH 1/4] Update tested Pydantic versions This also adds an exclusion for more recent versions of Python and older versions of Pydantic, as those aren't compatible. --- noxfile.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/noxfile.py b/noxfile.py index 1f6cd29..8021922 100644 --- a/noxfile.py +++ b/noxfile.py @@ -5,16 +5,30 @@ @session @parametrize( "pydantic", - ("2.0", "2.1", "2.2", "2.3", "2.4"), + ( + (2, 0), + (2, 1), + (2, 2), + (2, 3), + (2, 4), + (2, 5), + (2, 6), + (2, 7), + (2, 8), + (2, 9), + (2, 10), + ), ) -@parametrize("graphene", ("2.1.8", "2.1.9", "3.0", "3.1", "3.2", "3.3")) +@parametrize("graphene", ("2.1.8", "2.1.9", "3.0", "3.1", "3.2", "3.3", "3.4")) def tests(session, pydantic, graphene): - if sys.version_info > (3, 10) and pydantic in ("1.7", "1.8"): + if sys.version_info > (3, 10) and pydantic in ((1, 7), (1, 8)): return session.skip() if sys.version_info > (3, 10) and graphene <= "3": - # Graphene 2.x doesn't support Python 3.11 return session.skip() - session.install(f"pydantic=={pydantic}") + if sys.version_info > (3, 11) and pydantic < (2, 9): + return session.skip() + pydantic_version_string = ".".join([str(n) for n in pydantic]) + session.install(f"pydantic=={pydantic_version_string}") session.install(f"graphene=={graphene}") session.install("pytest", "pytest-cov", ".") session.run( From 47a5e94c04e2bd8c9ded5ca69b245c4c0df93da7 Mon Sep 17 00:00:00 2001 From: Rami Chowdhury Date: Mon, 9 Dec 2024 23:02:24 -0500 Subject: [PATCH 2/4] Add test to catch bug --- tests/test_registry.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_registry.py b/tests/test_registry.py index b8c875f..77ee7d7 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -58,3 +58,20 @@ def test_register_object_field_and_get_for_graphene_field(): field = r.get_object_field_for_graphene_field(GraphFoo, "name") assert field is not None assert field.annotation == str + + +def test_register_object_field_nested_model(): + """https://github.com/graphql-python/graphene-pydantic/issues/104""" + + class A(BaseModel): + x: str | None = None + y: list["A"] | None = None + + class P_A(PydanticInputObjectType): + class Meta: + model = A + + try: + P_A.resolve_placeholders() + except TypeError as e: + assert False, f"'10 / 5' raised an exception: {e}" From 877341483c6931ca2f9a33789ce71ca23926ff91 Mon Sep 17 00:00:00 2001 From: Rami Chowdhury Date: Mon, 9 Dec 2024 23:02:32 -0500 Subject: [PATCH 3/4] Remove argument --- graphene_pydantic/inputobjecttype.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/graphene_pydantic/inputobjecttype.py b/graphene_pydantic/inputobjecttype.py index 95f444d..08e4960 100644 --- a/graphene_pydantic/inputobjecttype.py +++ b/graphene_pydantic/inputobjecttype.py @@ -80,8 +80,8 @@ def __init_subclass_with_meta__( _meta=None, **options, ): - assert model and issubclass( - model, pydantic.BaseModel + assert ( + model and issubclass(model, pydantic.BaseModel) ), f'You need to pass a valid Pydantic model in {cls.__name__}.Meta, received "{model}"' assert isinstance( @@ -149,8 +149,6 @@ def resolve_placeholders(cls): model=target_type.model, ) fields_to_update[name] = graphene_field - meta.registry.register_object_field( - cls, name, pydantic_field, model=target_type.model - ) + meta.registry.register_object_field(cls, name, pydantic_field) # update the graphene side of things meta.fields.update(fields_to_update) From c932dd0affa28c0e1976b5ebb95dee2600e9bfb4 Mon Sep 17 00:00:00 2001 From: Rami Chowdhury Date: Mon, 9 Dec 2024 23:49:50 -0500 Subject: [PATCH 4/4] Lint --- graphene_pydantic/inputobjecttype.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphene_pydantic/inputobjecttype.py b/graphene_pydantic/inputobjecttype.py index 08e4960..c7d8a5e 100644 --- a/graphene_pydantic/inputobjecttype.py +++ b/graphene_pydantic/inputobjecttype.py @@ -80,8 +80,8 @@ def __init_subclass_with_meta__( _meta=None, **options, ): - assert ( - model and issubclass(model, pydantic.BaseModel) + assert model and issubclass( + model, pydantic.BaseModel ), f'You need to pass a valid Pydantic model in {cls.__name__}.Meta, received "{model}"' assert isinstance(