On 27 mar, 19:49, Justin Bronn <jbr...
> Isn't the checking of `self.null` that you've identified as the
> problem already in the `GeometryField.clean` method? Are you
> proposing a recursive call?
> I agree that GeometryField is ripe to be improved -- but I'm unclear
> on exactly what is the problem and the proposed solution here.
Thanks for answering Justin.
I'll show the problem with a simple example. Suppose the following
point = GeometryField(required=False)
Do you think the point field can be left blank and then the form
validates? Because "required" is an attribute used by the Field
superclass, one should assume that the point field could be left
blank, but because of GeometryField's not standard behaviour (/django/
contrib/gis/forms/fields.py, line 31), it raises a ValidationError.
This is because GeometryField checks a "null" attribute in its clean()
method, instead of "required". "null" isn't defined in any of the
standard Django forms' fields. I suppose that it was consciously made
that way for some reason, but I don't think it's worth breaking the
standard behaviour for form fields.
I see two ways of fixing this:
- Introduce a backwards-incompatible change so that GeometryField
doesn't use "null", and use "required" instead. I don't know if this
has impact in other parts of Django.
- Allow for "null" OR "required". If null is True or required is False
then the field should be allowed to be blank. This should be backwards-
I hope I made myself clearer this time. Opinions please? If this
should be fixed, and I seriously think it must, I'll open a ticket and
attach a patch.