graphql-python / graphene-pydantic

Integrate GraphQL with your Pydantic models
Other
229 stars 44 forks source link

AssertionError: Found different types with the same name in the schema: Foo, Foo. #34

Closed dantp-ai closed 3 years ago

dantp-ai commented 4 years ago

@necaris I get AssertionError: Found different types with the same name in the schema: Foo, Foo. if I run test_query from test_forward_refs.py twice!

necaris commented 4 years ago

@plopd Can you give us some more detail on how you're running it -- can you paste some code from your application where this is coming up?

dantp-ai commented 4 years ago

Given the same python environment I ran the code inside the test_forward_refs.py twice in succession.

dantp-ai commented 4 years ago

Your tests don't pass fully with pytest, given Python 3.6.0, where all the dependencies were installed with poetry!!

~/r/g/graphene-pydantic ❯❯❯ poetry run pytest                                                                               ✘ 130
======================================================= test session starts =======================================================
platform darwin -- Python 3.6.0, pytest-4.6.11, py-1.9.0, pluggy-0.13.1
rootdir: /../graphene_pydantic/graphene-pydantic
plugins: cov-2.7.1
collected 33 items / 1 errors / 32 selected

============================================================= ERRORS ==============================================================
___________________________________________ ERROR collecting tests/test_forward_refs.py ___________________________________________
tests/test_forward_refs.py:33: in <module>
    class Foo(PydanticObjectType):
.venv/lib/python3.6/site-packages/graphene/utils/subclass_with_meta.py:52: in __init_subclass__
    super_class.__init_subclass_with_meta__(**options)
graphene_pydantic/objecttype.py:95: in __init_subclass_with_meta__
    exclude_fields=exclude_fields,
graphene_pydantic/objecttype.py:47: in construct_fields
    field, registry, parent_type=obj_type, model=model
graphene_pydantic/converters.py:130: in convert_pydantic_field
    declared_type, field, registry, parent_type=parent_type, model=model
graphene_pydantic/converters.py:157: in convert_pydantic_type
    type_, field, registry, parent_type=parent_type, model=model
graphene_pydantic/converters.py:213: in find_graphene_type
    elif isinstance(type_, T.ForwardRef):
E   AttributeError: module 'typing' has no attribute 'ForwardRef'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================== 1 error in 4.43 seconds =====================================================
necaris commented 4 years ago

@plopd Thank you for finding this! We will have to add a better error message -- unfortunately the forward refs feature requires Python 3.7+ as in upstream Pydantic -- https://pydantic-docs.helpmanual.io/usage/postponed_annotations/ . So that test is not expected to pass on Python 3.6.

dantheman39 commented 4 years ago

@plopd Yes, ForwardRef isn't available in python 3.6, thanks for catching that. Note that there are other caveats with python 3.6 (Union Types not working specifically, due to 3.6's implementation of them).

So of course this code and the messaging can use some improvements, but in the meantime if you're able to use python 3.7 you'll have better results. Thanks again for finding the issue.

necaris commented 3 years ago

Closing this as it's been >3 months with no further action needed :smile: