Avoid cloning Q objects in assertQueries().

Review Request #12368 — Created June 13, 2022 and submitted — Latest diff uploaded




As a precaution, assertQueries() attempted to clone Q() objects
through a deepcopy. This ended up being a bad idea, for two reasons.

  1. Q() handles its own cloning logic already, and is careful about
    it. Mostly because of the second reason.

  2. 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 the InstanceState objects in
    RelationCounterField, due to weakref 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.