Repository navigation
Conversation
…e dropped or crash migrate (mongodb#640) * INTPYTHON-1082: Create indexes declared with ordering expressions * INTPYTHON-1082: Address review feedback on expression index handling * trim prose * trim prose * INTPYTHON-1082: Address second review round on expression index handling - remove_index() records the drop directly when collecting migration SQL instead of making a live listIndexes call. - get_pymongo_index_model() skips an index with untranslatable expressions before translating its condition, so an unsupported condition lookup no longer raises. * INTPYTHON-1082: Fix index removal with unsupported partial-filter conditions * INTPYTHON-1082: Warn for untranslatable expressions when Index.check omits W043 * trim text * Warn when an index is skipped for untranslatable expressions * Simplify index removal and deduplicate W043 tests * Consolidate index-existence checks and drop dead mocks * Only tolerate IndexNotFound when removing expression indexes (cherry picked from commit 4bf0186)
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved correctness issues affect cross-database checks, expression translation, and embedded-index cleanup.
3 open issues
What changed in this PR
Backports #640 to the 6.0.x backend, adding MongoDB index support for field-ordering expressions while retaining embedded-field column prefixes.
Changes:
- Translates supported
F()andOrderBy()expressions into index keys and aligns warnings with translation support. - Handles removal of expression indexes skipped by earlier versions.
- Adds regression tests and release notes.
| File | Description |
|---|---|
tests/schema_/test_embedded_model.py |
Tests embedded expression indexes with column prefixes. |
tests/indexes_/test_expressions.py |
Tests expression translation, skipping, and removal. |
tests/indexes_/test_checks.py |
Tests expression-index warnings. |
tests/indexes_/test_base.py |
Adds a custom index subclass test fixture. |
docs/releases/6.0.x.rst |
Documents fixes and upgrade guidance. |
django_mongodb_backend/schema.py |
Updates expression-index removal handling. |
django_mongodb_backend/indexes.py |
Implements expression translation and warning checks. |
django_mongodb_backend/features.py |
Clarifies support and adjusts expected test failures. |
Review effort: Balanced
|
Blocked by #646 |
There was a problem hiding this comment.
🟡 Changes recommended
An active moderate issue causes embedded-model expression indexes with conditions to generate partial filters at the wrong document path, so the index can match the wrong documents and requires a code fix plus regression coverage.
1 open issue
3 resolved since last review
Review effort: Lite
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the change is supported by regression tests and documented handling for expression indexes, warnings, embedded paths, and index removal.
No open issues 🎉
2 resolved since last review
Review effort: Lite
|
Closing this as not worth the effort to backport due to the need to handle |


INTPYTHON-1082 (https://jira.mongodb.org/browse/INTPYTHON-1082)
Backport of #640.
Changes in this PR
On 6.0.x, an index declared with an ordering expression such as
Index(F("priority").desc(), name="...")was silently skipped, andmigratecrashed onIndexsubclasses that reportcontains_expressions=False(django-tasks-db'sConditionalPartialIndex).F()andOrderBy()orderings now translate into MongoDB index keys; anything else, including NULLS FIRST/LAST, is skipped without raising.models.W043warning now matches whether the index is actually created.The only delta from #640 is keeping the
column_prefixparameter that 6.0.x still needs (main dropped it in the Django 6.1 update), on the rewrittenget_pymongo_index_modeland onSearchIndex.get_pymongo_index_model.Test Plan
column_prefixparameter (in the second commit).schemaandconstraintsapps pass;pre-commit run --all-filesis clean.Checklist
Checklist for Author
Checklist for Reviewer