#21496 closed Bug (fixed)
Django 1.6 django.contrib.gis GeometryField crashes on alternate widget
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | GIS | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
If I use a TextInput widget to edit a PointField, form validation crashes because the widget doesn't have a map_srid
.
The string representation of a Point using the default srid (4326) doesn't define the SRID, which is unfortunate.
>> p.srid 4326 >> str(p) 'POINT (-122.3996132001327055 37.7942941983347467)' >> p2 = GEOSGeometry('POINT (-122.3996132001327055 37.7942941983347467)') >> p2.srid None
I think the best solution would be to allow the field to transform the value into whatever the default is set as for the field, unless otherwise specified by the widget.
So something like the following PR would be required:
https://github.com/django/django/pull/1966
Change History (6)
comment:1 by , 11 years ago
Description: | modified (diff) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
comment:3 by , 11 years ago
I didn't mention this, but the other reason for moving the transform out of clean was because of another crash.
in _has_changed, this line fails:
data.transform(initial.srid)
Since to_python would then allow geom objects without srids... the srid from the field itself doesn't get applied unless you call clean(), which _has_changed does not.
My use of try...except was mostly habit from EAFP (http://docs.python.org/2/glossary.html)
comment:4 by , 11 years ago
Has patch: | set |
---|
So what about this PR: https://github.com/django/django/pull/1971
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
There are two parts in your proposed pull request. First of all, the crash concerning the missing map_srid is bad and should be fixed, clearly. But a simple
hasattr(self.widget, 'map_srid')
would be enough, at least at first sight.Then there is the part about where to convert the value into the srid of the field. This is debatable, but I'm currently not entirely convinced by your patch. I would probably move in
to_python
the srid attribution to the field srid when the value has no srid, but not thetransform
conversion. Anyway, this is a different issue, which we could discuss in another ticket.So I suggest to only fix something like this (which I would also backport to 1.6):
... with an appropriate test (I have the patch almost ready).