Skip to content

Commit b5f218c

Browse files
authored
Merge pull request pallets-eco#829 from pallets/deprecate-commit-on-teardown
deprecate COMMIT_ON_TEARDOWN
2 parents 13d6537 + b22958a commit b5f218c

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

CHANGES.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
Version 2.4.3
2+
-------------
3+
4+
Unreleased
5+
6+
- Deprecate ``SQLALCHEMY_COMMIT_ON_TEARDOWN`` as it can cause various
7+
design issues that are difficult to debug. Call
8+
``db.session.commit()`` directly instead. :issue:`216`
9+
10+
111
Version 2.4.2
212
-------------
313

414
Released 2020-05-25
515

616
- Fix bad pagination when records are de-duped. :pr:`812`
717

18+
819
Version 2.4.1
920
-------------
1021

docs/config.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ A list of configuration keys currently understood by the extension:
9898
``SQLALCHEMY_TRACK_MODIFICATIONS`` will warn if unset.
9999

100100
.. versionchanged:: 2.4
101+
* ``SQLALCHEMY_ENGINE_OPTIONS`` configuration key was added.
102+
* Deprecated keys
101103

102-
* ``SQLALCHEMY_ENGINE_OPTIONS`` configuration key was added.
103-
* Deprecated keys
104+
* ``SQLALCHEMY_NATIVE_UNICODE``
105+
* ``SQLALCHEMY_POOL_SIZE``
106+
* ``SQLALCHEMY_POOL_TIMEOUT``
107+
* ``SQLALCHEMY_POOL_RECYCLE``
108+
* ``SQLALCHEMY_MAX_OVERFLOW``
104109

105-
* ``SQLALCHEMY_NATIVE_UNICODE``
106-
* ``SQLALCHEMY_POOL_SIZE``
107-
* ``SQLALCHEMY_POOL_TIMEOUT``
108-
* ``SQLALCHEMY_POOL_RECYCLE``
109-
* ``SQLALCHEMY_MAX_OVERFLOW``
110+
.. versionchanged:: 2.4.3
111+
Deprecated ``SQLALCHEMY_COMMIT_ON_TEARDOWN``.
110112

111113

112114
Connection URI Format

flask_sqlalchemy/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ class to be used in place of :class:`Model`.
694694
695695
.. versionchanged:: 2.4
696696
The `use_native_unicode` parameter was deprecated.
697+
698+
.. versionchanged:: 2.4.3
699+
``COMMIT_ON_TEARDOWN`` is deprecated and will be removed in
700+
version 3.1. Call ``db.session.commit()`` directly instead.
697701
"""
698702

699703
#: Default query class used by :attr:`Model.query` and other queries.
@@ -843,6 +847,13 @@ def init_app(self, app):
843847
@app.teardown_appcontext
844848
def shutdown_session(response_or_exc):
845849
if app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']:
850+
warnings.warn(
851+
"'COMMIT_ON_TEARDOWN' is deprecated and will be"
852+
" removed in version 3.1. Call"
853+
" 'db.session.commit()'` directly instead.",
854+
DeprecationWarning,
855+
)
856+
846857
if response_or_exc is None:
847858
self.session.commit()
848859

tests/test_commit_on_teardown.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ def create():
2222

2323

2424
def test_commit_on_success(client):
25-
resp = client.post('/create')
25+
with pytest.warns(DeprecationWarning, match="COMMIT_ON_TEARDOWN"):
26+
resp = client.post('/create')
27+
2628
assert resp.status_code == 200
2729
assert client.get('/').data == b'Test one'
2830

2931

3032
def test_roll_back_on_failure(client):
31-
resp = client.post('/create', data={'fail': 'on'})
33+
with pytest.warns(DeprecationWarning, match="COMMIT_ON_TEARDOWN"):
34+
resp = client.post('/create', data={'fail': 'on'})
35+
3236
assert resp.status_code == 500
3337
assert client.get('/').data == b''

0 commit comments

Comments
 (0)