Opened 16 years ago

Closed 16 years ago

#7886 closed (fixed)

select_related handling with Oracle is (likely) broken

Reported by: Malcolm Tredinnick Owned by: Malcolm Tredinnick
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Erin Kelly Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I don't have any way to test this right now, but whilst fixing #7813, I realised there's some broken code in Query.results_iter. We have these lines

if resolve_columns:
    if self.select_fields:
        fields = self.select_fields + self.related_select_fields
    else:
        fields = self.model._meta.fields

(starting at line 200 in r8053). The problem is that self.related_select_fields isn't populated until pre_sql_setup() is called by as_sql(), which is called as part of the execute_sql() call lower down in that method. Thus, when we are querying for specific fields plus something using select_related(), we're going to be using an empty list as the second piece of the RHS, when it's really just a list that hasn't been populated yet.

I haven't really worked out how to fix this yet. Noting it so that I don't forget to do so later. Calling pre_sql_setup() earlier looks fragile. Maybe we have to populate the resolve-columns fields list inside the loop if it hasn't been populated yet (so on the first iteration), or something like that.

We also need to write a test for this. I can't immediately see how that branch is triggered, but that could be because it's late right at the moment.

(ikelly: adding you to the CC in case you have any good ideas here. Feel free to remove yourself, of course, if you're not interested.)

Change History (1)

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [8112]) Fixed #7886 -- Reordered some code in Query.results_iter() to ensure that all
the prequisites are correctly initialised prior to using them. Only affects
Oracle and other db backends requiring resolve_columns() (e.g. MS SQL?)

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