ChickenBenny commented on code in PR #77538:
URL: https://github.com/apache/airflow/pull/77538#discussion_r4692932228


##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -392,23 +393,22 @@ def _get_auth_role_public(self) -> str | None:
         """
         Return the role granted to anonymous users, or ``None`` if public 
access is disabled.
 
-        Reads ``[fab] auth_role_public`` from the Airflow config first so this 
works
-        during FastAPI startup, before any Flask application context exists. 
Falls back
-        to ``AUTH_ROLE_PUBLIC`` on the Flask app config when an app context is 
available,
-        which covers the legacy ``AUTH_ROLE_PUBLIC`` entry in 
``webserver_config.py``.
+        Reads ``[fab] auth_role_public`` from the Airflow config first, then 
falls back to
+        ``AUTH_ROLE_PUBLIC`` on the Flask app config, which covers the legacy 
entry in
+        ``webserver_config.py``.
         """
         role_public = conf.get("fab", "auth_role_public", fallback="") or None
         if role_public:
             return role_public
         if self.appbuilder is None:
             return None
-        try:
-            return self.appbuilder.app.config.get("AUTH_ROLE_PUBLIC", None)
-        except RuntimeError:
-            # ``appbuilder.app`` is a werkzeug ``LocalProxy``; accessing it 
outside a
-            # Flask application context raises ``RuntimeError``. This happens 
during
-            # FastAPI startup when ``get_fastapi_middlewares`` is invoked.
-            return None
+        # The API server runs FastAPI requests and startup without a Flask app 
context, where
+        # ``current_app`` raises, so read the Flask app it built in 
``get_fastapi_app``.
+        if self.flask_app is not None:

Review Comment:
   Done in 4c25f51a53: `_get_auth_role_public` now reads `current_app` when 
there is an app context, and falls back to `self.flask_app` otherwise. I 
removed the `flask_app` restore from `real_app_client` and from the new test 
helper, and the FAB unit tests pass without it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to