Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#19547 closed Bug (fixed)

Queryset.__or__ and caching of known related instances breaking

Reported by: mjtamlyn Owned by: aaugustin
Component: Database layer (models, ORM) Version: 1.5-beta-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you or together two querysets with known related instances then you can get some incorrect data:

If you do instance_1.foo_set.all() | instance_2.foo_set.all() then all of the foos will have foo.instance == instance1 even though foo.instance_id == instance2.pk.

I have a failing test case and a partial fix on github at https://github.com/mjtamlyn/django/compare/known-related-objects-queryset-or

The fix does ensure data is integral but it doesn't have the full efficiency improvement. I'm also working on a fix which solves the efficiency as well but it doesn't feel "right"...

Change History (5)

comment:1 Changed 3 years ago by mjtamlyn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Branch updated with a fix for the efficiency part of the test.

comment:2 Changed 3 years ago by aaugustin

  • Owner changed from mjtamlyn to aaugustin
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

The patch looks good.

comment:3 Changed 3 years ago by aaugustin

comment:4 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 07fbc6ae0e3b7742915b785c737b7e6e8a0e3503:

Fixed #19547 -- Caching of related instances.

When &'ing or |'ing querysets, wrong values could be cached, and crashes
could happen.

Thanks Marc Tamlyn for figuring out the problem and writing the patch.

comment:5 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

In 056ace0f395a58eeac03da9f9ee7e3872e1e407b:

[1.5.x] Fixed #19547 -- Caching of related instances.

When &'ing or |'ing querysets, wrong values could be cached, and crashes
could happen.

Thanks Marc Tamlyn for figuring out the problem and writing the patch.

Backport of 07fbc6a.

Note: See TracTickets for help on using tickets.
Back to Top