-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stabilize makemigrations when SITE_ID != 1 (#34787)
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: Your models in app(s): 'third_party_auth' have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them. 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
- Loading branch information
1 parent
1162614
commit ccf2b75
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
common/djangoapps/third_party_auth/migrations/0013_default_site_id_wrapper_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Generated by Django 4.2.13 on 2024-05-13 19:22 | ||
|
||
import common.djangoapps.third_party_auth.models | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sites', '0002_alter_domain_unique'), | ||
('third_party_auth', '0012_alter_ltiproviderconfig_site_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='ltiproviderconfig', | ||
name='site', | ||
field=models.ForeignKey(default=common.djangoapps.third_party_auth.models._get_site_id_from_settings, help_text='The Site that this provider configuration belongs to.', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)ss', to='sites.site'), | ||
), | ||
migrations.AlterField( | ||
model_name='oauth2providerconfig', | ||
name='site', | ||
field=models.ForeignKey(default=common.djangoapps.third_party_auth.models._get_site_id_from_settings, help_text='The Site that this provider configuration belongs to.', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)ss', to='sites.site'), | ||
), | ||
migrations.AlterField( | ||
model_name='samlconfiguration', | ||
name='site', | ||
field=models.ForeignKey(default=common.djangoapps.third_party_auth.models._get_site_id_from_settings, help_text='The Site that this SAML configuration belongs to.', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)ss', to='sites.site'), | ||
), | ||
migrations.AlterField( | ||
model_name='samlproviderconfig', | ||
name='site', | ||
field=models.ForeignKey(default=common.djangoapps.third_party_auth.models._get_site_id_from_settings, help_text='The Site that this provider configuration belongs to.', on_delete=django.db.models.deletion.CASCADE, related_name='%(class)ss', to='sites.site'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters