Opened 8 years ago

Closed 8 years ago

#24136 closed Bug (fixed)

GeoQueryset.extent() -> TypeError

Reported by: DemarsM Owned by: nobody
Component: GIS Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Im trying to get the extent of a GeoQueryset as explained in the doc:

class Feature(models.Model):
    geom_point = models.PointField(srid=3857, blank=True, null=True)
    geom_multipoint = models.MultiPointField(srid=3857, blank=True, null=True)
    geom_multilinestring = models.MultiLineStringField(srid=3857, blank=True, null=True)
    geom_multipolygon = models.MultiPolygonField(srid=3857, blank=True, null=True)
    geom_geometrycollection = models.GeometryCollectionField(srid=3857, blank=True, null=True)

for a specific feature, only one of the geometry field is not empty

featuresExtent = Feature.objects.all().extent()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\query.py", li
ne 119, in extent
    return self._spatial_aggregate(aggregates.Extent, **kwargs)
  File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\query.py", li
ne 505, in _spatial_aggregate
    return self.aggregate(geoagg=aggregate(agg_col, **agg_kwargs))['geoagg']
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 325, in a
ggregate
    return query.get_aggregation(using=self.db, force_subq=force_subq)
  File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\sql\query.py"
, line 76, in get_aggregation
    return super(GeoQuery, self).get_aggregation(using, force_subq)
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 397,
in get_aggregation
    in zip(query.aggregate_select.items(), result)
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 396,
in <genexpr>
    for (alias, aggregate), val
  File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\sql\query.py"
, line 88, in resolve_aggregate
    return connection.ops.convert_extent(value)
  File "C:\Python27\lib\site-packages\django\contrib\gis\db\backends\postgis\ope
rations.py", line 285, in convert_extent
    ll, ur = box[4:-1].split(',')
TypeError: 'NoneType' object has no attribute '__getitem__'

same error if I do:

Feature.objects.filter(pk=1).extent()

Change History (2)

comment:1 Changed 8 years ago by Claude Paroz

Easy pickings: set
Triage Stage: UnreviewedAccepted

https://groups.google.com/forum/#!topic/geodjango/VFgGGJfu6HM

This ticket aims to solve the TypeError: 'NoneType' object has no attribute '__getitem__' error when the return value of ST_Extent is None.

comment:2 Changed 8 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In e084ff01f27a28717eef471ff8e86b074d452f44:

Fixed #24136 -- Prevented crash when convert_extent input is None

Thanks Max Demars for the report.

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