Key migration component unit tests#8056
Conversation
📝 WalkthroughWalkthroughThis PR adds comprehensive test coverage for the ChangesMigration command tests and locale fix
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
specifyweb/specify/migration_utils/update_schema_config.py (1)
2040-2055:⚠️ Potential issue | 🟠 Major | ⚡ Quick winScope the upsert to English rows to avoid deleting non-English translations.
Line 2040 fetches all locale rows for the target FK, and Line 2055 deletes all but one. With Line 2050 now creating
language="en", this can still overwrite/delete existing non-English rows instead of upserting English only.Suggested fix
qs = Splocaleitemstr.objects.filter( itemdesc_id=itemdesc_id, itemname_id=itemname_id, + language="en", ).order_by("id")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@specifyweb/specify/migration_utils/update_schema_config.py` around lines 2040 - 2055, The current upsert logic on Splocaleitemstr queries all rows matching itemdesc_id and itemname_id (qs = Splocaleitemstr.objects.filter(...)) then creates or deduplicates without scoping by language, causing non-English translations to be deleted; modify the query and subsequent logic to restrict to language="en" (e.g., filter language="en" when building qs, check obj from that scoped qs, create with language="en" only if no en row exists, and delete duplicates only among en rows) so only English rows are upserted and non-English translations are preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@specifyweb/specify/migration_utils/update_schema_config.py`:
- Around line 2040-2055: The current upsert logic on Splocaleitemstr queries all
rows matching itemdesc_id and itemname_id (qs =
Splocaleitemstr.objects.filter(...)) then creates or deduplicates without
scoping by language, causing non-English translations to be deleted; modify the
query and subsequent logic to restrict to language="en" (e.g., filter
language="en" when building qs, check obj from that scoped qs, create with
language="en" only if no en row exists, and delete duplicates only among en
rows) so only English rows are upserted and non-English translations are
preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9ebd59b0-2eda-495c-a0a5-dda3ad7f033a
📒 Files selected for processing (3)
specifyweb/backend/stored_queries/tests/tests_legacy.pyspecifyweb/specify/migration_utils/update_schema_config.pyspecifyweb/specify/tests/test_run_key_migration_functions.py
💤 Files with no reviewable changes (1)
- specifyweb/backend/stored_queries/tests/tests_legacy.py
Fixes #8049
Add unit tests for key migration related functions...
Checklist
self-explanatory (or properly documented)
Testing instructions
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests