Opened 17 years ago

Closed 15 years ago

#2496 closed defect (fixed)

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

Reported by: rezzrovv Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: normal Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

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 (1)

query.py.patch (619 bytes) - added by rezzrovv 17 years ago.
patch for query error

Download all attachments as: .zip

Change History (8)

Changed 17 years ago by rezzrovv

Attachment: query.py.patch added

patch for query error

comment:1 Changed 17 years ago by anonymous

Keywords: 3534 added
Version: SVN

comment:2 Changed 17 years ago by Malcolm Tredinnick

Component: Core frameworkDatabase wrapper
Owner: changed from Adrian Holovaty to Malcolm Tredinnick

comment:3 Changed 16 years ago by Chris Beaven

Has patch: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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

comment:4 Changed 16 years ago by Malcolm Tredinnick

Keywords: qs-rf added

comment:5 Changed 16 years ago by Malcolm Tredinnick

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

comment:6 Changed 16 years ago by Malcolm Tredinnick

Keywords: qs-rf-fixed added; 3534 qs-rf removed

comment:7 Changed 15 years ago by Malcolm Tredinnick

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