Avoid cloning Q objects in assertQueries().
Review Request #12368 — Created June 13, 2022 and submitted
As a precaution,
assertQueries()
attempted to cloneQ()
objects
through adeepcopy
. This ended up being a bad idea, for two reasons.
Q()
handles its own cloning logic already, and is careful about
it. Mostly because of the second reason.A naive
deepcopy
ends up cloning the model instances and their
fields and other state, which has side effects and is incompatible
with some types of data (such as theInstanceState
objects in
RelationCounterField
, due toweakref
usage).We now just use the instances as normal, leaving it up to
Q()
to do
the right thing.
All unit tests using
assertQueries()
pass, and in-progress ones that
hit these issues no longer cause Python to crash.
Summary | ID |
---|---|
688143b5b0ec9ae048811c7548ce171036f75281 |