Skip to content

App context for model reflection causes circular import. #1138

Answered by davidism
TRezendes asked this question in Q&A
Discussion options

You must be logged in to vote

You need an active context when the code that needs it is evaluated. Module code is evaluated when it is imported. Therefore, you need a context active when you import the models, which happens as a side effect when you import the blueprints.

def create_app():
    ...

    with app.app_context():
        from .blueprint import bp
        app.register_blueprint(bp)

    ...
    return app

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TRezendes
Comment options

Answer selected by TRezendes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants