Skip to content
Merged
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
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ jobs:
name: tests
strategy:
matrix:
flask: ['<2.2', '<3.0', '<3.1', '<3.2', '']
os: [ubuntu-latest, macos-latest, windows-latest]
python: ['3.10', '3.11', '3.12', '3.13', '3.14', 'pypy-3.11']
exclude:
- flask: '<2.2'
python: '3.14'
- flask: '<2.2'
os: macos-latest
- flask: '<3.0'
os: macos-latest
- flask: '<3.1'
os: macos-latest
- flask: '<3.2'
os: macos-latest
- flask: '<2.2'
os: windows-latest
- flask: '<3.0'
os: windows-latest
- flask: '<3.1'
os: windows-latest
- flask: '<3.2'
os: windows-latest
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -33,6 +53,8 @@ jobs:
- run: python -m pip install --upgrade pip wheel
- run: pip install tox tox-gh-actions
- run: tox
env:
FLASK_VERSION: ${{ matrix.flask }}
coverage:
name: coverage
runs-on: ubuntu-latest
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"blinker",
"click",
"flask",
"Flask >= 2.1.0",
"jinja2",
"python-socketio >= 5.12.0",
"werkzeug",
]

[project.readme]
Expand All @@ -31,10 +36,12 @@ docs = [
"sphinx",
]
dev = [
"tox",
"flask-login",
"flask-session",
"pytest",
"pytest-cov",
"redis",
"tox",
]

[tool.setuptools]
Expand Down
19 changes: 14 additions & 5 deletions src/flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,13 +806,22 @@ def _handle_event(self, handler, message, namespace, sid, *args):
environ['saved_session'] = _ManagedSession(flask.session)
session_obj = environ['saved_session']
if hasattr(flask, 'globals') and \
hasattr(flask.globals, 'request_ctx'):
# update session for Flask >= 2.2
ctx = flask.globals.request_ctx._get_current_object()
hasattr(flask.globals, 'app_ctx'):
if hasattr(flask.globals.app_ctx, 'session'):
# get context for flask >= 3.2
ctx = flask.globals.app_ctx._get_current_object()
else:
# get context for Flask >= 2.2, < 3.2
ctx = flask.globals.request_ctx._get_current_object()
else: # pragma: no cover
# update session for Flask < 2.2
# get context for Flask < 2.2
ctx = flask._request_ctx_stack.top
ctx.session = session_obj
if hasattr(ctx, '_session'):
# update session for Flask >= 3.1.3
ctx._session = session_obj
else:
# update session for Flask < 3.1.3
ctx.session = session_obj
else:
# let Flask handle the user session
# for cookie based sessions, this effectively freezes the
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python =
[testenv]
commands=
pip install -e .
pip install "flask{env:FLASK_VERSION:}" "werkzeug{env:FLASK_VERSION:}"
pytest -p no:logging --cov=flask_socketio --cov-branch --cov-report=term-missing --cov-report=xml
deps=
pytest
Expand Down