• 
      

    Avoid cloning Q objects in assertQueries().

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

    Information

    Djblets
    release-3.x

    Reviewers

    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.

    Summary ID
    Avoid cloning Q objects in assertQueries().
    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.
    688143b5b0ec9ae048811c7548ce171036f75281
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-3.x (b9ee050)