Skip to content

The application context is not passed to webserver_config.py #32747

@slmg

Description

@slmg

Apache Airflow version

2.6.3

What happened

Hi, I would like to pass a custom WSGI Middleware to the underlying flask server.

I could theoretically do so in webserver_config.py by accessing flask.current_app:

# webserver_config.py

from flask import current_app
from airflow.www.fab_security.manager import AUTH_REMOTE_USER

class MyAuthMiddleware:
    def __init__(self, wsgi_app) -> None:
        self.wsgi_app = wsgi_app

    def __call__(self, environ: dict, start_response):
        print("--> Custom authenticating logic")
        environ["REMOTE_USER"] = "username"
        return self.wsgi_app(environ, start_response)

current_app.wsgi_app = MyAuthMiddleware(current_app.wsgi_app)

AUTH_TYPE = AUTH_REMOTE_USER

But for this to work the application context should be pushed while reading the webserver config.

Thus

flask_app.config.from_pyfile(settings.WEBSERVER_CONFIG, silent=True)
should become

with flask_app.app_context():
    flask_app.config.from_pyfile(settings.WEBSERVER_CONFIG, silent=True)

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions