]> 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:17 +0000 (18:16 -0400)
commitc92f166792a8119bd9243aa8a2fd2038413996f4
treea0409563d0dcbdcb7a5c3c3be80d0c74dbfeb452
parent25427957d41e76c59e8b90a0a441e25733984979
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
(cherry picked from commit d6db28556b095dc85fff3e0e09b0e70358a9538b)
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