#26789: ORM produces query with NULL instead of empty geometry
----------------------------+--------------------------------------
Reporter: sir-sigurd | Owner: sir-sigurd
Type: Bug | Status: assigned
Component: GIS | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Comment (by rcoup):
Simplistic fix could be something like (`BaseSpatialField`):
{{{
def get_db_prep_save(self, value, connection):
"""
Prepare the value for saving in the database.
"""
if value or isinstance(value, Geometry):
return connection.ops.Adapter(self.get_prep_value(value))
else:
return None
}}}
A test case I used to track down the issue
(`gis_tests/geoapp/test_regress.py`):
{{{
def test_empty_assignment(self):
c = Country.objects.get(name='Texas')
c.mpoly = 'SRID=4326;MULTIPOLYGON EMPTY'
self.assertIsInstance(c.mpoly, geos.MultiPolygon)
self.assertTrue(c.mpoly.empty)
c.save()
c.refresh_from_db()
self.assertIsInstance(c.mpoly, geos.MultiPolygon)
self.assertTrue(c.mpoly.empty)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26789#comment:5>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.bdf8b996ef0a268eff501c2b44923487%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.