Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10660 closed (fixed)

GeometryField doesn't honor "required" attribute

Reported by: framos Owned by: framos
Component: GIS Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The Django documentation says that every form field can be left blank or not depending on the required attribute. However, Django gis' GeometryField doesn't honor that attribute, but uses another called null instead.

A simple example to see the problem with the current GeometryField:

class MyForm(forms.Form):
    point = GeometryField(required=False)

According to the documentation, the form should validate when the "point" field is left blank, but actually it raises ValidationError. The offending code is in [source:/django/trunk/django/contrib/gis/forms/fields.py@8565#L31 line 31 of /django/trunk/django/contrib/gis/forms/fields.py].

I suppose (hope) that the use of null in GeometryField was a deliberate decision made for some reason, but I think the standard behavior for form fields must be maintained.

I see two choices for fixing this:

  1. 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.
  2. Allow for "null" OR "required". If null is True OR required is False then the field should be allowed to be blank. One option would be calling the parent class' (Field) clean() method. This should be backwards-compatible AFAIK.

I can submit a patch when a design decision is reached.

See also this discussion at Django-developers.

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by jbronn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

(In r10634) Fixed #10660 -- GeometryField no longer requires srid/null keywords, and now respects required; coordinate transformations now done inside gis.forms.GeometryField -- benefit being that OSMGeoAdmin no longer requires 900913 entry in spatial_ref_sys thus enabling it to work with MySQL/Oracle spatial backends; added tests for geographic forms.

comment:2 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.