fix(migrations): actually drop _customer_location_uc (list == set no-op) - #42642
Draft
mikebridge wants to merge 1 commit into
Draft
fix(migrations): actually drop _customer_location_uc (list == set no-op)#42642mikebridge wants to merge 1 commit into
mikebridge wants to merge 1 commit into
Conversation
Migration df3d7e2eb9a4 intended to drop the legacy 3-column unique constraint _customer_location_uc (database_id, schema, table_name) from the tables table, but passed a list to generic_find_uq_constraint_name, whose body compares columns == set(uq['column_names']). list == set is always False in Python, so the constraint was never found and never dropped — a silent no-op. Databases migrated through it therefore still carry the constraint, which leaks across catalogs (no catalog leg) and diverges from schemas built from model metadata, where the model's 4-column constraint exists instead. A row can occupy (database_id, schema, table_name) across catalogs, passing every catalog-aware app-level check and then hitting an opaque IntegrityError only on migrated databases. Fix in two parts: - generic_find_uq_constraint_name coerces its columns argument to a set, removing the foot-gun for all callers (existing set-passing callers unaffected). - A take-2 migration re-attempts the drop with exact set matching. No-op where the constraint is already absent; the model's 4-column constraint can never match a 3-column set comparison. Downgrade restores the legacy constraint best-effort, mirroring the tolerant posture of its original creator. Verified on SQLite and PostgreSQL: fresh full-chain upgrade, then downgrade (constraint recreated) and re-upgrade (constraint dropped), with uq_tables_uuid untouched throughout. Fixes sc-112173. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42642 +/- ##
==========================================
- Coverage 65.44% 65.44% -0.01%
==========================================
Files 2810 2810
Lines 159362 159363 +1
Branches 36372 36372
==========================================
- Hits 104301 104298 -3
- Misses 53019 53022 +3
- Partials 2042 2043 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SUMMARY
Migration
df3d7e2eb9a4(2024) intended to drop the legacy 3-column unique constraint_customer_location_uc(database_id, schema, table_name)fromtables, but passed a list togeneric_find_uq_constraint_name, whose body comparescolumns == set(uq["column_names"]).list == setis alwaysFalsein Python, so the constraint was never found and never dropped — a silent no-op.Consequences on databases migrated through it:
catalogleg) is still present, while schemas built from model metadata (create_all, e.g. CI) carry the model's intended 4-column constraint(database_id, catalog, schema, table_name)instead — so CI cannot reproduce production failure shapes.(database_id, schema, table_name)across catalogs: creating the same table under a different catalog passes every catalog-aware app-level check and then hits an opaqueIntegrityErroronly on migrated databases.Two-part fix:
generic_find_uq_constraint_namenow coerces itscolumnsargument to a set (parameter widened toCollection[str]), removing the foot-gun for all callers. Existing set-passing callers are unaffected.16755d4ca4ae) re-attempts the drop with exact set matching. It is a harmless no-op where the constraint is already absent, and the model's 4-column constraint can never match a 3-column set comparison, so it is not at risk. Downgrade restores the legacy constraint best-effort (rows written after the drop may legitimately collide across catalogs), mirroring the tolerant try/except posture of the constraint's original creator.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — schema-only change.
TESTING INSTRUCTIONS
pytest tests/unit_tests/utils/test_core.py -k generic_find_uq— 3 tests: the list-argument regression pin (fails against the pre-fix helper), the set-argument happy path, and the exact-match guarantee (a 3-column lookup never matches the model's 4-column constraint).superset db upgrade(clean), thensuperset db downgrade(constraint recreated:_customer_location_uc (database_id, schema, table_name)), thensuperset db upgrade(constraint dropped), withuq_tables_uuiduntouched throughout. On a database that still carries the legacy constraint, the upgrade drops it; on one that never had it, the lookup finds nothing and the migration no-ops.ADDITIONAL INFORMATION
ALTER TABLE ... DROP CONSTRAINTontables(or a no-op lookup); sub-second on PostgreSQL/MySQL, table-rebuild via batch mode on SQLite. No data movement, no downtime expected.🤖 Generated with Claude Code