Code

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#9364 closed (fixed)

Spatial queries don't work on inherited geometry fields

Reported by: jbronn Owned by: jbronn
Component: GIS Version: 1.0
Severity: Keywords: gis inheritance
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jbronn)

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>,))

Attachments (1)

handle_inherited_geofields.diff (10.1 KB) - added by jbronn 6 years ago.
Patch that allows GeoQuerySet methods to operate on inherited geometry fields; includes tests.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by jbronn

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by jbronn

  • Needs tests set
  • Status changed from new to assigned

I want tests before I'll commit this -- but this appears to solve the problem by using the correct database table name for the inherited geometry field.

Changed 6 years ago by jbronn

Patch that allows GeoQuerySet methods to operate on inherited geometry fields; includes tests.

comment:3 Changed 6 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [9336]) Fixed #9364 -- now uses the appropriate database table for inherited GeometryFields; now uses the SpatialBackend booleans in tests.

comment:4 Changed 6 years ago by jbronn

(In [9337]) Fixed #9364 -- now uses the appropriate database table for inherited GeometryFields; now uses the SpatialBackend booleans in tests.

Backport of r9336 from trunk.

comment:5 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.