Django

Code

Ticket #9364 (closed: fixed)

Opened 3 months ago

Last modified 2 months ago

Spatial queries don't work on inherited geometry fields

Reported by: jbronn Assigned to: jbronn
Milestone: post-1.0 Component: GIS
Version: 1.0 Keywords: gis inheritance
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

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

handle_inherited_geofields.diff (10.1 kB) - added by jbronn on 11/05/08 08:18:38.
Patch that allows GeoQuerySet? methods to operate on inherited geometry fields; includes tests.

Change History

10/14/08 11:17:38 changed by jbronn

  • needs_better_patch changed.
  • description changed.
  • needs_tests changed.
  • needs_docs changed.

11/04/08 11:20:29 changed by jbronn

  • status changed from new to assigned.
  • needs_tests set to 1.

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.

11/05/08 08:18:38 changed by jbronn

  • attachment handle_inherited_geofields.diff added.

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

11/05/08 11:56:09 changed by jbronn

  • status changed from assigned to closed.
  • resolution set to fixed.

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

11/05/08 12:06:25 changed 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.


Add/Change #9364 (Spatial queries don't work on inherited geometry fields)




Change Properties
Action