]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Don't cache a query that has before_compile modifications
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Oct 2019 15:34:37 +0000 (11:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Oct 2019 22:16:02 +0000 (18:16 -0400)
commitd6db28556b095dc85fff3e0e09b0e70358a9538b
treeb74991aeeebcf8ab666816049d3aae17d566abdb
parent172d99a8a1282b534aeadafebdd2af0162758931
Don't cache a query that has before_compile modifications

The :class:`.BakedQuery` will not cache a query that was modified by a
:meth:`.QueryEvents.before_compile` event, so that compilation hooks that
may be applying ad-hoc modifications to queries will take effect on each
run.  In particular this is helpful for events that modify queries used in
lazy loading as well as eager loading such as "select in" loading.  In
order to re-enable caching for a query modified by this event, a new
flag ``bake_ok`` is added; see :ref:`baked_with_before_compile` for
details.

A longer term plan to provide a new form of SQL caching should solve this
kind of issue more comprehensively.

Fixes: #4947
Change-Id: I5823c4fa00e7b6d46a2e8461b02d8b16605a6ed0
doc/build/changelog/unreleased_13/4947.rst [new file with mode: 0644]
doc/build/orm/extensions/baked.rst
lib/sqlalchemy/ext/baked.py
lib/sqlalchemy/orm/events.py
lib/sqlalchemy/orm/query.py
test/ext/test_baked.py
test/orm/test_events.py