Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7873 closed (fixed)

GEOSGeometry equality operator fails on None

Reported by: denis@… Owned by: jbronn
Component: GIS Version: gis
Severity: Keywords: geos equals
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jbronn)

>>> from django.contrib.gis.geos import *
>>> Point(0, 0) == None
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/", line 170, in __eq__
    return self.equals_exact(other)
  File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/", line 318, in equals_exact
    return geos_equalsexact(self.ptr, other.ptr, float(tolerance))
AttributeError: 'NoneType' object has no attribute 'ptr'

Attachments (1)

geos_eq.diff (571 bytes) - added by jbronn 8 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 8 years ago by jbronn

Description: modified (diff)
Keywords: equals added
Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to jbronn
Patch needs improvement: unset

I agree that a TypeError should be raised instead -- at least an error is raised, so this is non-critical at the moment.

Changed 8 years ago by jbronn

Attachment: geos_eq.diff added

comment:2 Changed 8 years ago by jbronn

Status: newassigned

On second thought, it would be more pythonic to return False instead. The attached patch does that.

comment:3 Changed 8 years ago by jbronn

milestone: 1.0 beta

comment:4 Changed 8 years ago by denis@…

Agreed about the return False.
This might be useful to check if a geometry is set. While some people will write
if not self.geom:
Others will write:
if self.geom == None:

comment:5 Changed 8 years ago by jbronn

Resolution: fixed
Status: assignedclosed

(In [8040]) gis: Fixed #7873, GEOSGeometry equivalence comparison with None should not raise an exception. Thanks, Denis.

comment:6 Changed 5 years ago by Jacob

milestone: 1.0 beta

Milestone 1.0 beta deleted

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