Skip to content

[fix]: Prevent FallbackMixin from generating spurious migrations #1231#604

Open
shivsubh wants to merge 1 commit intoopenwisp:masterfrom
shivsubh:issues/1231-fallback-fileds-db-migrations
Open

[fix]: Prevent FallbackMixin from generating spurious migrations #1231#604
shivsubh wants to merge 1 commit intoopenwisp:masterfrom
shivsubh:issues/1231-fallback-fileds-db-migrations

Conversation

@shivsubh
Copy link

@shivsubh shivsubh commented Mar 3, 2026

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: openwisp/openwisp-controller#1231

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #.

Please open a new issue if there isn't an existing issue yet.

Description of Changes

Please describe these changes.

Screenshot

Please include any relevant screenshots.

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
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

The changes modify the FallbackMixin class in openwisp_utils/fields.py to address unnecessary migration generation. The fallback argument in __init__ is now optional with a default value of None instead of being required. The deconstruct method no longer explicitly restores the fallback value to kwargs, preventing Django's migration system from detecting changes when default settings are modified without explicit field argument changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description explains the changes and references an issue, but fails to complete the required checklist sections completely and leaves template placeholders unfilled. Complete the Reference to Existing Issue section by replacing # with the actual issue number. Fill in the Description of Changes section with the content provided above the checklist. Mark the unchecked test and documentation items appropriately if intentionally skipped.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the fix for preventing spurious migrations caused by the FallbackMixin fallback kwarg serialization issue.
Linked Issues check ✅ Passed The changes address issue #1231 by removing fallback from deconstruct() and making it optional in init, preventing spurious migrations when default settings change.
Out of Scope Changes check ✅ Passed All changes are scoped to addressing the fallback migration issue with minimal modifications to FallbackMixin as required.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link

Coverage Status

coverage: 97.249% (-0.001%) from 97.25%
when pulling ecf6e09 on shivsubh:issues/1231-fallback-fileds-db-migrations
into 288e8cc on openwisp:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Fallback fields generate DB migrations when default settings are changed

2 participants