Opened 3 years ago

Last modified 17 months ago

#18565 new Bug

Point object doesn't work in queyset.extra params argument

Reported by: jbzdak@… Owned by: nobody
Component: GIS Version: 1.4
Severity: Normal 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

While using GIS objects in queryset lookups (like distance etc) works OK, these objects don't work when passed as params argument in queryset.extra function.

queryset = queryset.extra(where=['mm_hitchhiker_search("move_move"."path", %s, %s)'], params=[from_waypoint.point, to_waypoint.point])

Change History (3)

comment:1 Changed 3 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Type changed from Uncategorized to Bug

Oh, I didn't provide an explanation.

The following snippet:

queryset = queryset.extra(where=['mm_hitchhiker_search("move_move"."path", %s, %s)'], params=[from_waypoint.point, to_waypoint.point])

produces this error:

Internal Server Error: /search/ajax/hitchhiker
Traceback (most recent call last):
 (...)
  File "/home/jb/programs/meetmove/django/template/defaulttags.py", line 145, in render
    len_values = len(values)
  File "/home/jb/programs/meetmove/django/db/models/query.py", line 85, in __len__
    self._result_cache = list(self.iterator())
  File "/home/jb/programs/meetmove/django/db/models/query.py", line 291, in iterator
    for row in compiler.results_iter():
  File "/home/jb/programs/meetmove/django/db/models/sql/compiler.py", line 763, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/jb/programs/meetmove/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/home/jb/programs/meetmove/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/home/jb/programs/meetmove/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
DatabaseError: can't adapt type 'Point'
[04/Jul/2012 07:14:56] "POST /search/ajax/hitchhiker HTTP/1.1" 500 15796

EDIT(aaugustin): removed profanity.

Last edited 3 years ago by aaugustin (previous) (diff)

comment:2 Changed 3 years ago by claudep

  • Triage Stage changed from Unreviewed to Accepted

Basically, a standard WhereNode go through: as_sql() -> make_atom() (from contrib.gis) -> lvalue.process() -> field.get_db_prep_lookup() -> connection.ops.Adapter(point)

An ExtraWhere is much more simple and just inject the params in the sql string.

I suspect this will end up in a documentation fix to explain the limitation (or tell to manually call the Adapter() method?). We need an ORM guru to confirm.

comment:3 Changed 17 months ago by ramiro

  • Summary changed from Point object doesn't work in quqeyset.extra params argument to Point object doesn't work in queyset.extra params argument
Note: See TracTickets for help on using tickets.
Back to Top