Skip to content

Commit 05ad77a

Browse files
committed
[fix]: Prevent FallbackMixin from generating spurious migrations
The deconstruct() method was serializing the fallback kwarg into Django migration files. This caused new migrations to be generated whenever the fallback default value changed in settings, even though no actual database schema change had occurred. The fix removes fallback from deconstruct() so Django no longer tracks it as part of the field migration state. fallback is also made optional in __init__ (defaulting to None) so existing migrations that omit the kwarg remain valid. Fixes: #1231
1 parent cc2e830 commit 05ad77a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

openwisp_utils/fields.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ class FallbackMixin(object):
4848
"""
4949

5050
def __init__(self, *args, **kwargs):
51-
self.fallback = kwargs.pop("fallback")
51+
self.fallback = kwargs.pop("fallback", None)
5252
opts = dict(blank=True, null=True, default=None)
5353
opts.update(kwargs)
5454
super().__init__(*args, **opts)
5555

5656
def deconstruct(self):
5757
name, path, args, kwargs = super().deconstruct()
58-
kwargs["fallback"] = self.fallback
5958
return (name, path, args, kwargs)
6059

6160
def from_db_value(self, value, expression, connection):

tests/test_project/tests/test_model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,9 @@ def test_fallback_decimal_field(self):
180180
book.save(update_fields=["price"])
181181
book.refresh_from_db(fields=["price"])
182182
self.assertEqual(book.price, 56)
183+
184+
def test_fallback_field_deconstruct(self):
185+
field = OrganizationRadiusSettings._meta.get_field("is_active")
186+
name, path, args, kwargs = field.deconstruct()
187+
self.assertNotIn("fallback", kwargs)
188+

0 commit comments

Comments
 (0)