Opened 16 years ago

Closed 16 years ago

#6018 closed (fixed)

[patch] depth handling in fill_table_cache broken when using select_related(depth=1).extra()

Reported by: Matthias Urlichs <smurf@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qs-rf-fixed
Cc: marcin@…, matthias@…, gabor@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As reported by marcin@… in #3275:

There is a bug in the way depth is handled in fill_table_cache, see the attached patch for a test case. When you specify a non-zero depth fill_table_cache goes one relationship too deep which causes get_cached_row not to handle all the columns from select_related.

This bug shows up when you use extra on that QuerySet: the extra fields to select should immediately follow columns handled by get_cached_row, but instead they get data from the relationship that fill_table_cache added and get_cached_row skipped.


I'm re-posting this bug (and his patches) here because #3275 is, essentially, an unrelated ticket; IMHO this here patch should go into mainline ASAP.

Attachments (1)

select_related.diff (1.2 KB ) - added by Matthias Urlichs <smurf@…> 16 years ago.
One-character patch plus one-line testcase

Download all attachments as: .zip

Change History (7)

by Matthias Urlichs <smurf@…>, 16 years ago

Attachment: select_related.diff added

One-character patch plus one-line testcase

comment:1 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf added

comment:2 by Gábor Farkas <gabor@…>, 16 years ago

Cc: gabor@… added

the description is slightly incorrect, because this bug happens also when not using extra(),
for an example see #4789

comment:3 by Matthias Urlichs <smurf@…>, 16 years ago

Triage Stage: UnreviewedReady for checkin

Note: The patch in #4789 has a more extensive test case.

It also was already marked as ready before being prematurely closed as duplicate, which is why I am changing this ticket's state to "ready for check-in" now.

comment:4 by Malcolm Tredinnick, 16 years ago

(In [6755]) queryset-refactor: Fixed an off-by-one error when filling the select-related
case. Only affects people using select_related() with the "depth" parameter
*and* extra(select=...) simultaneously. Refs #6018. Thanks, Matthias Urlichs.

comment:5 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf-fixed added; qs-rf removed
Triage Stage: Ready for checkinAccepted

comment:6 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

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