Skip to content

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

Description

@robertfirek

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions