Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Fix for Werkzeug 2.1. #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

Version 2.0
-----------

- Add support for Werkzeug 2.1.


Version 1.1
-----------

Expand Down
17 changes: 5 additions & 12 deletions flask_sqlalchemy_session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,11 @@ def __init__(self, session_factory, app=None):
:class:`~sqlalchemy.orm.session.Session`
:param app: a :class:`~flask.Flask` application
"""
super(flask_scoped_session, self).__init__(
session_factory,
scopefunc=_app_ctx_stack.__ident_func__)
# the _app_ctx_stack.__ident_func__ is the greenlet.get_current, or
# thread.get_ident if no greenlets are used.
# each Flask request is launched in a seperate greenlet/thread, so our
# session is unique per request
# _app_ctx_stack looks like internal API but is the only way to get to
# the active application context without adding logic to figure out
# whether threads, greenlets, or something else is used to create new
# application contexts. Keep in mind to refactor if Flask changes its
# public/private API towards this.
try:
from greenlet import getcurrent as scopefunc
except ImportError:
scopefunc = None # let sqlalchemy used default Threading
super(flask_scoped_session, self).__init__(session_factory, scopefunc=scopefunc)
if app is not None:
self.init_app(app)

Expand Down
15 changes: 7 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import os
from setuptools import setup

if sys.version_info < (2, 6):
raise Exception("Flask-SQLAlchemy-Session requires Python 2.6 or higher.")

# Hard linking doesn't work inside VirtualBox shared folders. This means that
# you can't use tox in a directory that is being shared with Vagrant,
# since tox relies on `python setup.py sdist` which uses hard links. As a
Expand All @@ -38,14 +35,16 @@
'Intended Audience :: Developers',
'Environment :: Web Environment',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
],
install_requires=["sqlalchemy>=0.9", "Flask>=0.9", "Werkzeug>=0.6.1"],
tests_require=["pytest>=2.6", "mock>=1.0"],
install_requires=["sqlalchemy", "Flask", "Werkzeug"],
tests_require=["pytest"],
extras_require={
'docs': ["Sphinx>=1.2.3", "alabaster>=0.6.3"]
'docs': ["Sphinx", "alabaster"]
}
)
6 changes: 2 additions & 4 deletions tests/test_flask_sqlalchemy_session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
from unittest import mock

import pytest
try:
from unittest import mock
except ImportError:
import mock
from flask import Flask
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, sessionmaker
Expand Down