Fixed #28896 -- Reallowed filtering a queryset with GeometryField=None.

Regression in 58da81a5a3.
This commit is contained in:
Sergey Fedoseev 2017-12-06 14:59:30 +05:00 committed by Tim Graham
parent 10bfa876be
commit da71e4bb08
3 changed files with 7 additions and 0 deletions

View File

@ -167,6 +167,8 @@ class BaseSpatialField(Field):
def get_prep_value(self, value):
obj = super().get_prep_value(value)
if obj is None:
return None
# When the input is not a geometry or raster, attempt to construct one
# from the given string input.
if isinstance(obj, GEOSGeometry):

View File

@ -21,3 +21,5 @@ Bugfixes
* Fixed a regression in caching of a ``GenericForeignKey`` when the referenced
model instance uses more than one level of multi-table inheritance
(:ticket:`28856`).
* Reallowed filtering a queryset with ``GeometryField=None`` (:ticket:`28896`).

View File

@ -385,6 +385,9 @@ class GeoLookupTest(TestCase):
# Puerto Rico should be NULL (it's a commonwealth unincorporated territory)
self.assertEqual(1, len(nullqs))
self.assertEqual('Puerto Rico', nullqs[0].name)
# GeometryField=None is an alias for __isnull=True.
self.assertCountEqual(State.objects.filter(poly=None), nullqs)
self.assertCountEqual(State.objects.exclude(poly=None), validqs)
# The valid states should be Colorado & Kansas
self.assertEqual(2, len(validqs))