From 8bc147192c8e7174f9e0c9b55b2f5461f7227bcf Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 27 Jul 2022 00:01:40 +0200 Subject: [PATCH] Fix Flask Login user setting for Flask 2.2 and Flask-Login 0.6.2 (#25318) The Google openid auth backend of ours had hard-coded way of seting the current user which was not compatible with Flask 2.2 With Flask-login 0.6.2 the user is stored in g module of flask, where before, it was stored in _request_ctx_stack. Unforatunately the google_openid rather than using _update_request_context_with_user set the user directly in context. In Flask-login 0.6.2 this stopped working. This change switches to use the _update_request_context_with_user method rather than directly storing user in context which works before and after the Flask-Login 0.6.2 change. --- .../providers/google/common/auth_backend/google_openid.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/airflow/providers/google/common/auth_backend/google_openid.py b/airflow/providers/google/common/auth_backend/google_openid.py index a267c0e63a1ca..dc6b2a4fc2e2e 100644 --- a/airflow/providers/google/common/auth_backend/google_openid.py +++ b/airflow/providers/google/common/auth_backend/google_openid.py @@ -23,7 +23,7 @@ import google import google.auth.transport.requests import google.oauth2.id_token -from flask import Response, _request_ctx_stack, current_app, request as flask_request # type: ignore +from flask import Response, current_app, request as flask_request # type: ignore from google.auth import exceptions from google.auth.transport.requests import AuthorizedSession from google.oauth2 import service_account @@ -101,8 +101,7 @@ def _lookup_user(user_email: str): def _set_current_user(user): - ctx = _request_ctx_stack.top - ctx.user = user + current_app.appbuilder.sm.lm._update_request_context_with_user(user=user) # type: ignore[attr-defined] T = TypeVar("T", bound=Callable)