Django

Code

Ticket #2496 (closed: fixed)

Opened 2 years ago

Last modified 6 months ago

select_related will cause table multiple times in FROM clause if table already in extra()

Reported by: rezzrovv Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 1

Description

If a QuerySet? is built or initialized with select_related and extra() and extra contains a table that will ultimately be iterated over through the select_related, that table will not be picked up in fill_table_cache. The result is a query with the table twice in the FROM clause and results in an DB error when executed (at least on postgresql, can't speak for any other DBs). Patch submitted. Example error from postgresql:

ProgrammingError?: 'ERROR: table name "client" specified more than once

Attachments

query.py.patch (0.6 kB) - added by rezzrovv on 08/07/06 14:36:42.
patch for query error

Change History

08/07/06 14:36:42 changed by rezzrovv

  • attachment query.py.patch added.

patch for query error

08/07/06 14:38:03 changed by anonymous

  • keywords set to 3534.
  • version set to SVN.

08/07/06 20:05:39 changed by mtredinnick

  • owner changed from adrian to mtredinnick.
  • component changed from Core framework to Database wrapper.

09/02/07 18:14:13 changed by SmileyChris

  • needs_better_patch set to 1.
  • has_patch set to 1.
  • needs_tests set to 1.
  • stage changed from Unreviewed to Accepted.

Issue looks like a valid bug, but that's a hackish patch

09/13/07 16:36:25 changed by mtredinnick

  • keywords changed from 3534 to 3534, qs-rf.

10/13/07 22:46:44 changed by mtredinnick

(In [6504]) queryset-refactor: Fixed handling of extra(tables=...). In passing, this solves a duplicate table / bad SQL problem. Refs #2496.

10/13/07 22:47:47 changed by mtredinnick

  • keywords changed from 3534, qs-rf to qs-rf-fixed.

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 #2496 (select_related will cause table multiple times in FROM clause if table already in extra())




Change Properties
Action