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

Using decorator @functions_framework.errorhandler makes the python script impossible to import #136

Closed
robertfirek opened this issue Jul 15, 2021 · 2 comments · Fixed by #137

Comments

@robertfirek
Copy link

Using decorator @functions_framework.errorhandler makes the python script impossible to import without creating an application.
Import produces the error:

AttributeError: module 'functions_framework' has no attribute 'errorhandler'

Example

Trying to start run 'importer.py' script produce the above error.

decorated.py

from typing import Tuple

from flask.typing import ResponseValue, StatusCode

import functions_framework


@functions_framework.errorhandler
def handle_exception(ex: Exception) -> Tuple[ResponseValue[str], StatusCode]:
    return "Unhandled exception", 500

importer.py

import decorated

if __name__ == '__main__':
    print("Imported")

Possible source of the issue

The error handler decorator is registered in functions_framework.create_app() and it is not available without calling this functons.

@di
Copy link
Member

di commented Jul 15, 2021

Thanks for reporting the issue @robertfirek. I have a proposed fix in #137, can you try it and let us know if it works for you?

You should be able to install from that branch with:

$ pip install https://github.com/GoogleCloudPlatform/functions-framework-python/tree/fix/136

@robertfirek
Copy link
Author

@di It works. Thank you.

@di di closed this as completed in #137 Jul 21, 2021
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 a pull request may close this issue.

2 participants