Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NameError for subscriptions with custom Type #468

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

LdwgWffnschmdt
Copy link
Contributor

When trying to initialize a GraphQL schema with a subscription returning a custom type, I experienced this error. It is easily fixed by properly wrapping the operation in the Resolver. I would appreciate a merge and maybe also a small update of the pip package.

Background: get_type_hints can't get the type hints for the wrapped method, because without knowing about the method it wraps the globalns can't be properly resolved and thus the return value is not found. This results in an error message similar to this one:

Traceback (most recent call last):
  File "/home/ludwig/BaseAsset.py", line 199, in <module>
    schema = graphql_schema(query=[],
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/site-packages/apischema/utils.py", line 400, in wrapper
    return wrapped(*args, **kwargs)
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/site-packages/apischema/graphql/schema.py", line 975, in graphql_schema
    sub_types = subscriber.types()
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/site-packages/apischema/serialization/serialized_methods.py", line 62, in types
    types = get_type_hints(self.func, include_extras=True)
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 1846, in get_type_hints
    value = _eval_type(value, globalns, localns)
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 326, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 696, in _evaluate
    self.__forward_value__ = _eval_type(
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 326, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "/home/ludwig/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 691, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
NameError: name 'BaseAsset' is not defined

@LdwgWffnschmdt
Copy link
Contributor Author

@wyfo could you please take a look at this?

@wyfo wyfo merged commit a73ed43 into wyfo:master Dec 12, 2022
@wyfo
Copy link
Owner

wyfo commented Dec 12, 2022

Sorry for the delay, I'd taken a too long break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants