Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#11741 closed (fixed)

PostgreSQL/PostGIS backend table quoting bug in nested queries

Reported by: nino@… Owned by: jbronn
Component: GIS Version: dev
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

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@… 15 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Alex Gaynor, 15 years ago

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

by jaklaassen@…, 15 years ago

Attachment: django-gis.diff added

comment:2 by jaklaassen@…, 15 years ago

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

comment:3 by jbronn, 15 years ago

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 by Cliff Dyer, 15 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Alex Gaynor, 15 years ago

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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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