Closed dantp-ai closed 3 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?
Given the same python environment I ran the code inside the test_forward_refs.py
twice in succession.
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 =====================================================
@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.
@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.
Closing this as it's been >3 months with no further action needed :smile:
@necaris I get
AssertionError: Found different types with the same name in the schema: Foo, Foo.
if I runtest_query
fromtest_forward_refs.py
twice!