#9364: Spatial queries don't work on inherited geometry fields
---------------------------------+------------------------------------------
          Reporter:  jbronn      |         Owner:  jbronn         
            Status:  new         |     Milestone:  post-1.0       
         Component:  GIS         |       Version:  1.0            
        Resolution:              |      Keywords:  gis inheritance
             Stage:  Unreviewed  |     Has_patch:  0              
        Needs_docs:  0           |   Needs_tests:  0              
Needs_better_patch:  0           |  
---------------------------------+------------------------------------------
Changes (by jbronn):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Old description:

> In the following models `TexasCity` inherits from `City`:
>
> {{{
> from django.contrib.gis.db import models
>
> class City(models.Model):
>     name = models.CharField(max_length=30)
>     point = models.PointField()
>     objects = models.GeoManager()
>
>     def __unicode__(self): return self.name
>
> class TexasCity(City):
>     tx_county = models.CharField(max_length=30)
>
>     def __unicode__(self):
>         return '%s (%s County)' % (self.name, self.tx_county)
> }}}
>
> When performing the following query:
> {{{
> In [4]: qs = TexasCity.objects.filter(point__distance_lte=(pnt, D(mi=5)))
> }}}
>
> This error is raised:
> {{{
> FieldError                                Traceback (most recent call
> last)
>
> /Users/jbronn/geodjango/<ipython console> in <module>()
>
> /Users/jbronn/hg/django/gis/django/db/models/manager.pyc in filter(self,
> *args, **kwargs)
>     100
>     101     def filter(self, *args, **kwargs):
> --> 102         return self.get_query_set().filter(*args, **kwargs)
>     103
>     104     def complex_filter(self, *args, **kwargs):
>
> /Users/jbronn/hg/django/gis/django/db/models/query.pyc in filter(self,
> *args, **kwargs)
>     487         set.
>     488         """
> --> 489         return self._filter_or_exclude(False, *args, **kwargs)
>     490
>     491     def exclude(self, *args, **kwargs):
>
> /Users/jbronn/hg/django/gis/django/db/models/query.pyc in
> _filter_or_exclude(self, negate, *args, **kwargs)
>     505             clone.query.add_q(~Q(*args, **kwargs))
>     506         else:
> --> 507             clone.query.add_q(Q(*args, **kwargs))
>     508         return clone
>     509
>
> /Users/jbronn/hg/django/gis/django/db/models/sql/query.pyc in add_q(self,
> q_object, used_aliases)
>    1246                 else:
>    1247                     self.add_filter(child, connector,
> q_object.negated,
> -> 1248                             can_reuse=used_aliases)
>    1249                 if connector == OR:
>    1250                     # Aliases that were newly added or not used
> at all need to
>
> /Users/jbronn/hg/django/gis/django/db/models/sql/query.pyc in
> add_filter(self, filter_expr, connector, negate, trim, can_reuse,
> process_extras)
>    1121             field, target, opts, join_list, last, extra_filters =
> self.setup_joins(
>    1122                     parts, opts, alias, True, allow_many,
> can_reuse=can_reuse,
> -> 1123                     negate=negate, process_extras=process_extras)
>    1124         except MultiJoin, e:
>    1125             self.split_exclude(filter_expr,
> LOOKUP_SEP.join(parts[:e.level]),
>
> /Users/jbronn/hg/django/gis/django/db/models/sql/query.pyc in
> setup_joins(self, names, opts, alias, dupe_multis, allow_many,
> allow_explicit_fk, can_reuse, negate, process_extras)
>    1449
>    1450         if pos != len(names) - 1:
> -> 1451             raise FieldError("Join on field %r not permitted." %
> name)
>    1452
>    1453         return field, target, opts, joins, last, extra_filters
>
> FieldError: Join on field 'point' not permitted.
> }}}

New description:

 In the following models `TexasCity` inherits from `City`:

 {{{
 from django.contrib.gis.db import models

 class City(models.Model):
     name = models.CharField(max_length=30)
     point = models.PointField()
     objects = models.GeoManager()

     def __unicode__(self): return self.name

 class TexasCity(City):
     tx_county = models.CharField(max_length=30)
     objects = models.GeoManager() # Why does this need to be explicit?

     def __unicode__(self):
         return '%s (%s County)' % (self.name, self.tx_county)
 }}}

 When performing the following query:
 {{{
 In [4]: qs = TexasCity.objects.distance(pnt)
 }}}

 This SQL is generated, which is incorrect (there is no "point" column on
 the `TexasCity` model):
 {{{
 In [23]: qs.query.as_sql()
 Out[23]:
 (u'SELECT (ST_distance_sphere("tz_texascity"."point",%s)) AS "distance",
 "tz_city"."id", "tz_city"."name", "tz_city"."point",
 "tz_texascity"."city_ptr_id", "tz_texascity"."tx_county" FROM
 "tz_texascity" INNER JOIN "tz_city" ON ("tz_texascity"."city_ptr_id" =
 "tz_city"."id")',
  (<django.contrib.gis.db.backend.postgis.adaptor.PostGISAdaptor object at
 0x319b610>,))
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9364#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to