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

Impossible to use get_type_hints in main file #49

Closed
ChristianSauer opened this issue May 14, 2020 · 2 comments · Fixed by #50
Closed

Impossible to use get_type_hints in main file #49

ChristianSauer opened this issue May 14, 2020 · 2 comments · Fixed by #50
Labels
bug Something isn't working

Comments

@ChristianSauer
Copy link

ChristianSauer commented May 14, 2020

get_type_hints is used by Pydantic, dacite etc. to create their model classes, so it'S kinda important.

Currentliy, this is broken in main.py:

Traceback (most recent call last):
  File "***\main.py", line 40, in ar_v4
    data = dacite.from_dict(RequestData2, message)
  File "***\venv\lib\site-packages\dacite\core.py", line 43, in from_dict
    data_class_hints = get_type_hints(data_class, globalns=config.forward_references)
  File "C:\dev\python3.8\lib\typing.py", line 1220, in get_type_hints
    base_globals = sys.modules[base.__module__].__dict__
KeyError: 'main'

reproduction:

install dacite
in main.py

import dacite
import dataclasses

@dataclasses.dataclass
class RequestData2:
    product_number: int

def hello_world(request):
    message = request.get_json()
    data = dacite.from_dict(RequestData2, message)
    return ""

post some data to it and observe the error.

Workaround:

create another file and place your data classes in them

@di di added the bug Something isn't working label May 14, 2020
@di di closed this as completed in #50 May 14, 2020
@di
Copy link
Member

di commented May 14, 2020

Thanks for the bug report! This is fixed in functions-framework==1.4.3.

@ChristianSauer
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants