Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22250 closed Bug (fixed)

Regression in 1.6.1->1.6.2 -- GIS sql compiler tries to generate sql for a non-concrete field

Reported by: gwahl@… Owned by: Anton Baklanov
Component: Database layer (models, ORM) Version: 1.6
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (10)

comment:1 by gwahl@…, 10 years ago

I check on master and the same issue exists.

comment:2 by Anton Baklanov, 10 years ago

Owner: changed from nobody to Anton Baklanov
Status: newassigned

I will try to figure out what's going on here.

comment:3 by Aymeric Augustin, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:4 by Anssi Kääriäinen <akaariai@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 21f208e66e6472b8db8cdfd7cd1102d71bb15733:

Fixed #22250 -- regression in gis compiler for non-concrete fields

Thanks to gwahl@… for the report.

comment:5 by Anssi Kääriäinen <akaariai@…>, 10 years ago

In a6a0800579c806d54af7edd425063be8de4051ab:

[1.7.x] Fixed #22250 -- regression in gis compiler for non-concrete fields

Thanks to gwahl@… for the report.

Backport of 21f208e66e from master

comment:6 by Anssi Kääriäinen <akaariai@…>, 10 years ago

In 31892af3f03fa75dd59a2f70beebb29993098778:

[1.6.x] Fixed #22250 -- regression in gis compiler for non-concrete fields

Thanks to gwahl@… for the report.

Backport of 21f208e66e from master

comment:7 by Tim Graham <timograham@…>, 10 years ago

In d57ba04d890bab2d5ebe494e5e23d7374d658036:

Added 1.6.3 release note for refs #22250.

comment:9 by Tim Graham <timograham@…>, 10 years ago

In 916f0de74ba00f65cc789c075ce94f7fba858976:

[1.6.x] Added 1.6.3 release note for refs #22250.

Backport of d57ba04d89 from master

comment:8 by Tim Graham <timograham@…>, 10 years ago

In 25da849896c86c382da6337e719ef57460a77c85:

[1.7.x] Added 1.6.3 release note for refs #22250.

Backport of d57ba04d89 from master

comment:9 by gwahl@…, 10 years ago

This fix worked for me, thanks.

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