Ticket #16110: geodjango_16110.diff

File geodjango_16110.diff, 2.2 KB (added by slinkp, 4 years ago)

second attempt patch to fix 16610, with test. a typo fixed

  • django/contrib/gis/forms/fields.py

     
    2626        # defaults (e.g., allow None).
    2727        self.srid = kwargs.pop('srid', None)
    2828        self.geom_type = kwargs.pop('geom_type', 'GEOMETRY')
    29         self.null = kwargs.pop('null', True)
     29        self.null = kwargs.pop('null', True)  # Never checked: stop passing this?
    3030        super(GeometryField, self).__init__(**kwargs)
    3131
    3232    def clean(self, value):
     
    3636        the value cannot be instantiated as a Geometry.
    3737        """
    3838        if not value:
    39             if self.null and not self.required:
    40                 # The geometry column allows NULL and is not required.
    41                 return None
    42             else:
     39            if self.required:
    4340                raise forms.ValidationError(self.error_messages['no_geom'])
     41            else:
     42                return None
    4443
    4544        # Trying to create a Geometry object from the form value.
    4645        try:
  • django/contrib/gis/tests/test_geoforms.py

     
    3434        fld = forms.GeometryField()
    3535        self.assertRaises(forms.ValidationError, fld.clean, None)
    3636
    37         # Still not allowed if `null=False`.
    38         fld = forms.GeometryField(required=False, null=False)
    39         self.assertRaises(forms.ValidationError, fld.clean, None)
    40 
    4137        # This will clean None as a geometry (See #10660).
    4238        fld = forms.GeometryField(required=False)
    4339        self.assertEqual(None, fld.clean(None))
    4440
     41        # We used to check the underlying db_field's nullability
     42        # and effectively override required=False. Don't do that anymore.
     43        # See #16610.
     44        fld = forms.GeometryField(required=False, null=False)
     45        self.assertEqual(None, fld.clean(None))
     46
     47
    4548    def test03_geom_type(self):
    4649        "Testing GeometryField's handling of different geometry types."
    4750        # By default, all geometry types are allowed.
Back to Top