Opened 14 years ago

Closed 14 years ago

#12690 closed (fixed)

Oracle related lookup query fails in geodjango

Reported by: Jani Tiainen Owned by: nobody
Component: GIS Version: dev
Severity: Keywords: oracle query orm lookup
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

MyModel.objects.filter(geomfield__relate=(geom, 'anyinteract') fails with exception:

Traceback (most recent call last): 
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/keygwt-core/keygwt_core/gis/services/service.py", line 104, in get_by_bounding_box count = qs.count()
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/db/models/query.py", line 324, in count return self.query.get_count(using=self.db)
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/db/models/sql/query.py", line 369, in get_count number = obj.get_aggregation(using=using)[None]
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/contrib/gis/db/models/sql/query.py", line 80, in get_aggregation return super(GeoQuery, self).get_aggregation(using)
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/db/models/sql/query.py", line 341, in get_aggregation result = query.get_compiler(using).execute_sql(SINGLE)
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/db/models/sql/compiler.py", line 674, in execute_sql cursor.execute(sql, params)
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/db/backends/util.py", line 22, in execute sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/home/KEYPRO/jtiai/src/django-workspaces/keycom/django-trunk/django/db/backends/__init__.py", line 215, in last_executed_query return smart_unicode(sql) % u_params TypeError: not all arguments converted during string formatting 

Reason is that sql string contains only one parameter placeholder, but u_params tuple contains two:

>>> print sql
'SELECT COUNT(*) FROM "MYMODEL" WHERE SDO_RELATE("MYMODEL"."GEOMFIELD", SDO_GEOMETRY(%s, 294914), \'mask=anyinteract)\' = \'TRUE\'' 
>>> print u_params
(u'POLYGON ((3393119.6060000001452863 6673712.9181599998846650, 3393122.0120799997821450 6673712.9181599998846650, 3393122.0120799997821450 6673716.2352799996733665, 3393119.6060000001452863 6673716.2352799996733665, 3393119.6060000001452863 6673712.9181599998846650))', u'anyinteract')

There is also typo, \'mask=anyinteract)\' should be \'mask=anyinteract\')

Change History (1)

comment:1 by jbronn, 14 years ago

Resolution: fixed
Status: newclosed

(In [12300]) Fixed #12690 -- Fixed SQL template used for Oracle's with SDO_RELATE function, added truncate_params attribute to spatial backend, and re-enabled the relate lookup tests. Thanks, jtiai, for the bug report.

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