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.
Using decorator
@functions_framework.errorhandlermakes the python script impossible to import without creating an application.Import produces the error:
Example
Trying to start run 'importer.py' script produce the above error.
decorated.py
importer.py
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.