Skip to content

Commit 95f5012

Browse files
authored
Merge pull request pallets-eco#727 from lbeaufort/699-default-track-modifications-to-false
Set SQLALCHEMY_TRACK_MODIFICATIONS to False by default
2 parents 3d3261f + 2d40657 commit 95f5012

File tree

5 files changed

+12
-45
lines changed

5 files changed

+12
-45
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Version 3.0.0
33

44
Unreleased
55

6+
- Set `SQLALCHEMY_TRACK_MODIFICATIONS` to `False` by default,
7+
remove deprecation warning (:pr:`727`)
8+
69

710
Version 2.4.0
811
-------------

docs/config.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ A list of configuration keys currently understood by the extension:
7070
**Deprecated** as of v2.4 and will be removed in v3.0.
7171
``SQLALCHEMY_TRACK_MODIFICATIONS`` If set to ``True``, Flask-SQLAlchemy will
7272
track modifications of objects and emit
73-
signals. The default is ``None``, which
74-
enables tracking but issues a warning
75-
that it will be disabled by default in
76-
the future. This requires extra memory
73+
signals. The default is ``False`` because
74+
this requires extra memory
7775
and should be disabled if not needed.
7876
``SQLALCHEMY_ENGINE_OPTIONS`` A dictionary of keyword args to send to
7977
:func:`~sqlalchemy.create_engine`. See

flask_sqlalchemy/__init__.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(self, db, autocommit=False, autoflush=True, **options):
138138
bind = options.pop('bind', None) or db.engine
139139
binds = options.pop('binds', db.get_binds(app))
140140

141-
if track_modifications is None or track_modifications:
141+
if track_modifications:
142142
_SessionSignalEvents.register(self)
143143

144144
SessionBase.__init__(
@@ -829,18 +829,9 @@ def init_app(self, app):
829829
app.config.setdefault('SQLALCHEMY_POOL_RECYCLE', None)
830830
app.config.setdefault('SQLALCHEMY_MAX_OVERFLOW', None)
831831
app.config.setdefault('SQLALCHEMY_COMMIT_ON_TEARDOWN', False)
832-
track_modifications = app.config.setdefault(
833-
'SQLALCHEMY_TRACK_MODIFICATIONS', None
834-
)
832+
app.config.setdefault('SQLALCHEMY_TRACK_MODIFICATIONS', False)
835833
app.config.setdefault('SQLALCHEMY_ENGINE_OPTIONS', {})
836834

837-
if track_modifications is None:
838-
warnings.warn(FSADeprecationWarning(
839-
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
840-
'will be disabled by default in the future. Set it to True '
841-
'or False to suppress this warning.'
842-
))
843-
844835
# Deprecation warnings for config keys that should be replaced by SQLALCHEMY_ENGINE_OPTIONS.
845836
utils.engine_config_warning(app.config, '3.0', 'SQLALCHEMY_POOL_SIZE', 'pool_size')
846837
utils.engine_config_warning(app.config, '3.0', 'SQLALCHEMY_POOL_TIMEOUT', 'pool_timeout')

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def app(request):
1111
app = flask.Flask(request.module.__name__)
1212
app.testing = True
1313
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
14-
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1514
return app
1615

1716

tests/test_config.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ def app_nr(app):
1818

1919
class TestConfigKeys:
2020

21-
def test_defaults(self, app):
21+
def test_defaults(self, app, recwarn):
2222
"""
2323
Test all documented config values in the order they appear in our
2424
documentation: http://flask-sqlalchemy.pocoo.org/dev/config/
2525
"""
26-
# Our pytest fixture for creating the app sets
27-
# SQLALCHEMY_TRACK_MODIFICATIONS, so we undo that here so that we
28-
# can inspect what FSA does below:
29-
del app.config['SQLALCHEMY_TRACK_MODIFICATIONS']
3026

31-
with pytest.warns(fsa.FSADeprecationWarning) as records:
32-
fsa.SQLAlchemy(app)
27+
fsa.SQLAlchemy(app)
3328

34-
# Only expecting one warning for the track modifications deprecation.
35-
assert len(records) == 1
29+
# Expecting no warnings for default config
30+
assert len(recwarn) == 0
3631

3732
assert app.config['SQLALCHEMY_DATABASE_URI'] == 'sqlite:///:memory:'
3833
assert app.config['SQLALCHEMY_BINDS'] is None
@@ -43,28 +38,9 @@ def test_defaults(self, app):
4338
assert app.config['SQLALCHEMY_POOL_TIMEOUT'] is None
4439
assert app.config['SQLALCHEMY_POOL_RECYCLE'] is None
4540
assert app.config['SQLALCHEMY_MAX_OVERFLOW'] is None
46-
assert app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] is None
41+
assert app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] is False
4742
assert app.config['SQLALCHEMY_ENGINE_OPTIONS'] == {}
4843

49-
def test_track_modifications_warning(self, app, recwarn):
50-
51-
# pytest fixuture sets SQLALCHEMY_TRACK_MODIFICATIONS = False
52-
fsa.SQLAlchemy(app)
53-
54-
# So we shouldn't have any warnings
55-
assert len(recwarn) == 0
56-
57-
# Let's trigger the warning
58-
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = None
59-
fsa.SQLAlchemy(app)
60-
61-
# and verify it showed up as expected
62-
assert len(recwarn) == 1
63-
expect = 'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead' \
64-
' and will be disabled by default in the future. Set it' \
65-
' to True or False to suppress this warning.'
66-
assert recwarn[0].message.args[0] == expect
67-
6844
def test_uri_binds_warning(self, app, recwarn):
6945
# Let's trigger the warning
7046
del app.config['SQLALCHEMY_DATABASE_URI']

0 commit comments

Comments
 (0)