﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7886	select_related handling with Oracle is (likely) broken	Malcolm Tredinnick	Malcolm Tredinnick	"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

{{{
#!python
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.)
  "		closed	Database layer (models, ORM)	dev		fixed		Erin Kelly	Unreviewed	0	0	0	0	0	0
