Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support Flask Session 0.7 #38072

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion airflow/www/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@

from flask import request
from flask.sessions import SecureCookieSessionInterface
from flask_session.sessions import SqlAlchemySessionInterface

try:
from flask_session.sqlalchemy import SqlAlchemySessionInterface

FLASK_SESSION_070_PLUS = True
except ImportError:
from flask_session.sessions import SqlAlchemySessionInterface

FLASK_SESSION_070_PLUS = False


class SessionExemptMixin:
Expand All @@ -36,6 +44,43 @@ def save_session(self, *args, **kwargs):
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,
cleanup_n_requests: int | None = None,
):
sa_session_iface_kw = {
"app": app,
"table": table,
"key_prefix": key_prefix,
"use_signer": use_signer,
"permanent": permanent,
}
if FLASK_SESSION_070_PLUS:
sa_session_iface_kw.update(
{
"client": db,
"sequence": sequence,
"schema": schema,
"bind_key": bind_key,
"sid_length": sid_length,
"cleanup_n_requests": cleanup_n_requests,
}
)
else:
sa_session_iface_kw["db"] = db
super().__init__(**sa_session_iface_kw)


class AirflowSecureCookieSessionInterface(SessionExemptMixin, SecureCookieSessionInterface):
"""Session interface that exempts some routes and stores session data in a signed cookie."""
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
# "flask-session>=0.4.0,!=0.6.*,<0.8",
"flask-session @ git+https://github.com/pallets-eco/flask-session.git@development",
"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.
Expand Down Expand Up @@ -1206,6 +1207,9 @@ Homepage = "https://airflow.apache.org/"
Twitter = "https://twitter.com/ApacheAirflow"
YouTube = "https://www.youtube.com/channel/UCSXwxpWZQ7XZ1WL3wqevChA/"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.envs.default]
python = "3.8"
platforms = ["linux", "macos"]
Expand Down
Loading