Skip to content

Conversation

@Code-Eat-Rabbit
Copy link
Owner

@Code-Eat-Rabbit Code-Eat-Rabbit commented Oct 17, 2025

Describe your changes:

I worked on fixing a bug where foreign key constraints caused unnecessary version updates during ingestion. The root cause was that the _table_constraints_handler function, responsible for patching table constraints, did not include referredColumns in its unique key generation for foreign keys. This led to foreign keys with identical constraintType and columns but varying referredColumns (e.g., department.id vs public.department.id) being incorrectly identified as the same constraint, resulting in spurious reordering and version changes.

My changes introduce a new helper function _get_constraint_key that incorporates referredColumns into the unique key for foreign keys. The _table_constraints_handler now uses this improved key generation, ensuring that foreign key constraints are correctly matched and preventing unnecessary version bumps.

I tested these changes by:

  1. Creating a specific test case to reproduce the bug, demonstrating the instability caused by differing referredColumns.
  2. Verifying that the fix correctly handles these scenarios, ensuring stability.
  3. Adding new unit tests to ingestion/tests/unit/metadata/ingestion/models/test_table_constraints.py to cover foreign key matching with and without referredColumns variations.
  4. Running existing unit tests to confirm no regressions were introduced.

Type of change:

  • Bug fix
  • Improvement
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes #17987: Fix foreign key versioning bug
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

Open in Cursor Open in Web

Co-authored-by: yourton.ma <yourton.ma@gmail.com>
Repository owner deleted a comment from cursor bot Oct 20, 2025
@Code-Eat-Rabbit Code-Eat-Rabbit deleted the cursor/reproduce-and-fix-foreign-key-versioning-bug-32ce branch October 20, 2025 02:50
Repository owner deleted a comment from github-actions bot Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants