Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#11741 closed (fixed)

PostgreSQL/PostGIS backend table quoting bug in nested queries

Reported by: nino@… Owned by: jbronn
Component: GIS Version: master
Severity: Keywords: PostGIS Postgresql
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This issue occurs when using a spatial query as a subselect. The spatial predicate's table alias is quoted when it should not be.

E.g.:

>>> MyGeoTable.objects.filter(geometry__intersects=geom).values_list('fid', flat=True).distinct().query.as_nested_sql()
('SELECT DISTINCT U0."ogc_fid" FROM "my_geo_table" U0 WHERE ST_Intersects("U0"."split", %s)', (<django.contrib.gis.db.backend.postgis.adaptor.PostGISAdaptor object at 0xb6618c2c>,))

In the above ST_Intersects clause, the alias U0 is quoted. This happens here,I believe:
http://code.djangoproject.com/browser/django/trunk/django/contrib/gis/db/backend/postgis/query.py#L256

I have not patched it yet, as I'm not clear yet how.

Attachments (1)

django-gis.diff (1.8 KB) - added by jaklaassen@… 6 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The issue looks to be that the global quote_name shouldn't be use there, but instead Query.quote_name_unless_alias.

Changed 6 years ago by jaklaassen@…

comment:2 Changed 6 years ago by jaklaassen@…

I think the attached diffs will fix the problem. GeoWhereNode can pass the quote function through to get_geo_where_clause.

comment:3 Changed 6 years ago by jbronn

  • milestone set to 1.2
  • Owner changed from nobody to jbronn
  • Status changed from new to assigned
  • Version changed from 1.1 to SVN

Confirmed as a bug. A patch to fix this will be available after multi-db support lands.

comment:4 Changed 6 years ago by jcd

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 6 years ago by Alex

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [11872]) [soc2009/multidb] Fixed #11741 -- Updates to the spatial backends (e.g., re-enabled POSTGIS_VERSION setting); added geometry backend module. Patch from Justin Bronn.

comment:6 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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