From c2d6cb50211edf679242e091ac2980ff345cc5b8 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 16 Apr 2024 08:01:17 +0200 Subject: [PATCH] Remove support for assigning `None` to a `SplitField` This behavior wasn't documented and didn't fully work: it breaks as soon as you try to save a model with a `None` value. --- model_utils/fields.py | 3 --- tests/test_fields/test_split_field.py | 4 ---- 2 files changed, 7 deletions(-) diff --git a/model_utils/fields.py b/model_utils/fields.py index 1cd2d17..69188bb 100644 --- a/model_utils/fields.py +++ b/model_utils/fields.py @@ -208,9 +208,6 @@ class SplitDescriptor: def __get__(self, instance, owner): if instance is None: raise AttributeError('Can only be accessed via an instance.') - content = instance.__dict__[self.field.name] - if content is None: - return None return SplitText(instance, self.field.name, self.excerpt_field_name) def __set__(self, obj, value): diff --git a/tests/test_fields/test_split_field.py b/tests/test_fields/test_split_field.py index c053fa1..6028f89 100644 --- a/tests/test_fields/test_split_field.py +++ b/tests/test_fields/test_split_field.py @@ -53,10 +53,6 @@ class SplitFieldTests(TestCase): with self.assertRaises(AttributeError): Article.body - def test_none(self): - a = Article(title='Some Title', body=None) - self.assertEqual(a.body, None) - def test_assign_splittext(self): a = Article(title='Some Title') a.body = self.post.body