Django

Code

Ticket #6018 (closed: fixed)

Opened 6 months ago

Last modified 3 weeks ago

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

Reported by: Matthias Urlichs <smurf@smurf.noris.de> Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: qs-rf-fixed Cc: marcin@elksoft.pl, matthias@urlichs.de, gabor@nekomancer.net
Triage Stage: Accepted Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

As reported by marcin@elksoft.pl 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

select_related.diff (1.2 kB) - added by Matthias Urlichs <smurf@smurf.noris.de> on 11/23/07 04:49:59.
One-character patch plus one-line testcase

Change History

11/23/07 04:49:59 changed by Matthias Urlichs <smurf@smurf.noris.de>

  • attachment select_related.diff added.

One-character patch plus one-line testcase

11/27/07 06:33:44 changed by mtredinnick

  • keywords set to qs-rf.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

11/28/07 01:01:20 changed by Gábor Farkas <gabor@nekomancer.net>

  • cc changed from marcin@elksoft.pl, matthias@urlichs.de to marcin@elksoft.pl, matthias@urlichs.de, gabor@nekomancer.net.

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

11/28/07 02:20:15 changed by Matthias Urlichs <smurf@smurf.noris.de>

  • stage changed from Unreviewed to Ready 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.

11/29/07 16:07:58 changed by mtredinnick

(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.

11/29/07 16:08:33 changed by mtredinnick

  • keywords changed from qs-rf to qs-rf-fixed.
  • stage changed from Ready for checkin to Accepted.

04/26/08 21:50:16 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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


Add/Change #6018 ([patch] depth handling in fill_table_cache broken when using select_related(depth=1).extra())




Change Properties
Action