You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ta...@apache.org on 2024/02/28 08:41:24 UTC

(airflow) branch flask-session-060 created (now 3f72f68474)

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

taragolis pushed a change to branch flask-session-060
in repository https://gitbox.apache.org/repos/asf/airflow.git


      at 3f72f68474 [PoC] Flask Session 0.6

This branch includes the following new commits:

     new 3f72f68474 [PoC] Flask Session 0.6

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(airflow) 01/01: [PoC] Flask Session 0.6

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

taragolis pushed a commit to branch flask-session-060
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 3f72f684747c0a21189a71b34b439d364c5df659
Author: Andrey Anshin <An...@taragol.is>
AuthorDate: Wed Feb 28 06:04:05 2024 +0400

    [PoC] Flask Session 0.6
---
 airflow/www/session.py | 36 ++++++++++++++++++++++++++++++++++++
 pyproject.toml         |  3 ++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/airflow/www/session.py b/airflow/www/session.py
index 763b909ae0..95184856bd 100644
--- a/airflow/www/session.py
+++ b/airflow/www/session.py
@@ -16,10 +16,14 @@
 # under the License.
 from __future__ import annotations
 
+import inspect
+
 from flask import request
 from flask.sessions import SecureCookieSessionInterface
 from flask_session.sessions import SqlAlchemySessionInterface
 
+_SA_SESSION_INTERFACE_KEYS = set(inspect.signature(SqlAlchemySessionInterface.__init__).parameters.keys())
+
 
 class SessionExemptMixin:
     """Exempt certain blueprints/paths from autogenerated sessions."""
@@ -36,6 +40,38 @@ class SessionExemptMixin:
 class AirflowDatabaseSessionInterface(SessionExemptMixin, SqlAlchemySessionInterface):
     """Session interface that exempts some routes and stores session data in the database."""
 
+    def __init__(
+        self,
+        *,
+        app,
+        db,
+        table: str = "session",
+        sequence=None,
+        schema=None,
+        bind_key=None,
+        key_prefix: str = "",
+        use_signer: bool = False,
+        permanent: bool = True,
+        sid_length: int = 32,
+    ):
+        sa_session_iface_kw = {
+            "app": app,
+            "db": db,
+            "table": table,
+            "key_prefix": key_prefix,
+            "use_signer": use_signer,
+            "permanent": permanent,
+        }
+        if "sequence" in _SA_SESSION_INTERFACE_KEYS:
+            sa_session_iface_kw["sequence"] = sequence
+        if "schema" in _SA_SESSION_INTERFACE_KEYS:
+            sa_session_iface_kw["schema"] = schema
+        if "bind_key" in _SA_SESSION_INTERFACE_KEYS:
+            sa_session_iface_kw["bind_key"] = bind_key
+        if "sid_length" in _SA_SESSION_INTERFACE_KEYS:
+            sa_session_iface_kw["sid_length"] = sid_length
+        super().__init__(**sa_session_iface_kw)
+
 
 class AirflowSecureCookieSessionInterface(SessionExemptMixin, SecureCookieSessionInterface):
     """Session interface that exempts some routes and stores session data in a signed cookie."""
diff --git a/pyproject.toml b/pyproject.toml
index 9857c71066..2110597ba9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -92,7 +92,8 @@ dependencies = [
     "flask-caching>=1.5.0",
     # Flask-Session 0.6 add new arguments into the SqlAlchemySessionInterface constructor as well as
     # all parameters now are mandatory which make AirflowDatabaseSessionInterface incopatible with this version.
-    "flask-session>=0.4.0,<0.6",
+    # For avoiding any surprises in update in the next version, we add only compatibility only with Flask-Session 0.6.
+    "flask-session>=0.4.0,<=0.6",
     "flask-wtf>=0.15",
     # Flask 2.3 is scheduled to introduce a number of deprecation removals - some of them might be breaking
     # for our dependencies - notably `_app_ctx_stack` and `_request_ctx_stack` removals.