-
Notifications
You must be signed in to change notification settings - Fork 555
Remove db_constraint on TranslatedField as translations are not unique #24812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
diox
wants to merge
5
commits into
mozilla:master
Choose a base branch
from
diox:translations-remove-db-constraint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
434f282
Remove db_constraint on TranslatedField as translations are not unique
diox 70534bd
Migration to remove constraints, test proving they are gone
diox 985110a
Rewrite migration as RunPython
diox cc20a8a
This shouldn't be needed anymore
diox e88c351
Additional test
diox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
48 changes: 48 additions & 0 deletions
48
src/olympia/translations/migrations/0004_remove_legacy_constraints.py
This file contains hidden or 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,48 @@ | ||
| # Generated by Django 5.2.13 on 2026-04-28 21:26 | ||
|
|
||
| from django.db import migrations, router | ||
|
|
||
|
|
||
| def remove_legacy_translations_constraints(apps, schema_editor): | ||
| """ | ||
| Remove Foreign Key constraints to Translations.id - TranslatedField should | ||
| now be using db_constraint: False as there can be multiple translation rows | ||
| sharing the same id, one per locale per translated string. | ||
| """ | ||
| Translation = apps.get_model('translations', 'Translation') | ||
| models_related_to_translations = { | ||
| f.related_model | ||
| for f in Translation._meta.get_fields(include_hidden=True) | ||
| if f.auto_created and not f.concrete and (f.one_to_one or f.one_to_many) | ||
| } | ||
| connection = schema_editor.connection | ||
| with connection.cursor() as cursor: | ||
| for model in models_related_to_translations: | ||
| constraints = connection.introspection.get_constraints( | ||
| cursor, model._meta.db_table | ||
| ) | ||
| for name, info in constraints.items(): | ||
| if info['foreign_key'] == (Translation._meta.db_table, 'id'): | ||
| schema_editor.execute( | ||
| schema_editor._delete_fk_sql(model, name), params=None | ||
| ) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| # We're going to execute ALTER TABLE statements that are not supported | ||
| # inside a transaction, so disable transaction management to avoid | ||
| # "Executing DDL statements while in a transaction on databases that can't | ||
| # perform a rollback is prohibited" error. | ||
| atomic = False | ||
|
|
||
| dependencies = [ | ||
| ('translations', '0003_puretranslation_purifiedmarkdowntranslation'), | ||
| # Depend on these apps as they use TranslatedField | ||
| ('addons', '0060_backfill_last_content_review_status'), | ||
| ('versions', '0052_delete_enable_source_builder_waffle_switch'), | ||
| ('bandwagon', '0010_fix_default_locale_spanish'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(remove_legacy_translations_constraints, lambda *args: None) | ||
| ] |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#24894 proves just removing
--skip-restrict-fk-on-non-standard-keyin MySQL 8.4 without the changes from this PR loudly fails in CI.