fix: stabilize makemigrations when SITE_ID != 1 #34787
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some models in third_party_auth used settings.SITE_ID as a field default, which caused Django to say migrations were out of sync whenever settings.SITE_ID happened to be anything other than 1 for any developer:
This could easily happen if a developer is testing out site configuration or site-specific theming and ends up with a SITE_ID other than 1.
The fix, inspired by a StackOverflow answer [1], is to simply create a wrapper function for the dynamic default value. The wrapper function, rather than the current value of SITE_ID, will be serialized to the migraiton file.
This commit includes a migration file, but from a database perspective, the migration is a no-op.
[1] https://stackoverflow.com/a/12654998