Opened 11 years ago

Closed 11 years ago

Last modified 9 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: no UI/UX: no


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


>>> 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:

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

Attachments (1)

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

Download all attachments as: .zip

Change History (7)

comment:1 Changed 11 years ago by Alex Gaynor

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

Changed 11 years ago by jaklaassen@…

Attachment: django-gis.diff added

comment:2 Changed 11 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 11 years ago by jbronn

milestone: 1.2
Owner: changed from nobody to jbronn
Status: newassigned
Version: 1.1SVN

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

comment:4 Changed 11 years ago by Cliff Dyer

Triage Stage: UnreviewedAccepted

comment:5 Changed 11 years ago by Alex Gaynor

Resolution: fixed
Status: assignedclosed

(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 9 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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