You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/07/26 22:02:06 UTC

[airflow] branch main updated: Fix Flask Login user setting for Flask 2.2 and Flask-Login 0.6.2 (#25318)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 8bc147192c Fix Flask Login user setting for Flask 2.2 and Flask-Login 0.6.2 (#25318)
8bc147192c is described below

commit 8bc147192c8e7174f9e0c9b55b2f5461f7227bcf
Author: Jarek Potiuk <ja...@polidea.com>
AuthorDate: Wed Jul 27 00:01:40 2022 +0200

    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.
---
 airflow/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 a267c0e63a..dc6b2a4fc2 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 @@ from typing import Callable, Optional, TypeVar, cast
 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)