﻿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
22250	Regression in 1.6.1->1.6.2 -- GIS sql compiler tries to generate sql for a non-concrete field	gwahl@…	Anton Baklanov	"When upgrading from 1.6.1 to 1.6.2, I encountered a new error in my application. Basically, a non-concrete field is ending up in `query.related_select_cols`, then `SQLCompiler.get_columns` tries to use the field's column to build sql, when the field doesn't even have a column. The error manifests as trying to call `quote_name(None)`.


{{{
  File ""django/django/db/models/query.py"", line 220, in iterator
    for row in compiler.results_iter():
  File ""django/django/db/models/sql/compiler.py"", line 709, in results_iter
    for rows in self.execute_sql(MULTI):
  File ""django/django/db/models/sql/compiler.py"", line 772, in execute_sql
    sql, params = self.as_sql()
  File ""django/django/db/models/sql/compiler.py"", line 82, in as_sql
    out_cols, s_params = self.get_columns(with_col_aliases)
  File ""django/django/contrib/gis/db/models/sql/compiler.py"", line 88, in get_columns
    r = self.get_field_select(field, table, col)
  File ""django/django/contrib/gis/db/models/sql/compiler.py"", line 207, in get_field_select
    field_sel = sel_fmt % self._field_column(field, alias, column)
  File ""django/django/contrib/gis/db/models/sql/compiler.py"", line 248, in _field_column
    self.connection.ops.quote_name(column or field.column))
  File ""django/django/db/backends/postgresql_psycopg2/operations.py"", line 97, in quote_name
    if name.startswith('""') and name.endswith('""'):
AttributeError: 'NoneType' object has no attribute 'startswith'
}}}

The backported fix for #21413, commit 0f272629, was the commit that introduced the bug.

In `get_default_columns`, the GIS sql compiler uses `get_fields_with_model`: <https://github.com/django/django/blob/master/django/contrib/gis/db/models/sql/compiler.py#L127>

While the normal compiler uses `get_concrete_fields_with_model`: <https://github.com/django/django/blob/master/django/db/models/sql/compiler.py#L296>

Changing the GIS compiler to use `get_concrete_fields_with_model` fixes the issue.  I'm not anywhere near familiar enough with this code to get a minimal test case, so I'm hoping someone else can help and get this fixed.
"	Bug	closed	Database layer (models, ORM)	1.6	Release blocker	fixed			Accepted	0	0	0	0	0	0
