Skip to content

Conversation

@waltaskew
Copy link
Contributor

@waltaskew waltaskew commented Oct 16, 2025

Ensure both referred and constrained columns reported by get_multi_foreign_keys are in the same order matching the constraint declaration. Uses information for the unique constraint corresponding to the foreign key constraint in order to ensure its columns are ordered correctly.

Previously, the CONSTRAINT_COLUMN view in the information schema was used to retrieve the referred columns, and that view offers no information about column order. Instead, we use the KEY_COLUMN_USAGE view for the corresponding unique constraint, which is ordered.

This requires consulting the REFERENTIAL_CONSTRAINTS view in order to find the unique constraint associated with the foreign key. Unfortunately, this view has a bug in the emulator related to cross-schema foreign keys. I had to skip a test for cross-schema foreign keys due to the emulator issue. I've confirmed a real spanner does not have this issue.

fixes: #779

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. label Oct 16, 2025
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 20, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 20, 2025
Ensure both referred and constrained columns reported by
`get_multi_foreign_keys` are in the same order matching the constraint
declaration. Uses information for the unique constraint corresponding
to the foreign key constraint in order to ensure its columns are
ordered correctly.

Previously, the `CONSTRAINT_COLUMN` view in the information schema was
used to retrieve the referred columns, and that view offers no
information about column order. Instead, we use the KEY_COLUMN_USAGE
view for the corresponding unique constraint, which is ordered.

This requires consulting the `REFERENTIAL_CONSTRAINTS` view in order
to find the unique constraint associated with the foreign
key. Unfortunately, this view has a [bug in the
emulator](GoogleCloudPlatform/cloud-spanner-emulator#279)
related to cross-schema foreign keys. I had to skip a test for
cross-schema foreign keys due to the emulator issue. I've confirmed a
real spanner does not have this issue.

fixes: googleapis#779
@waltaskew waltaskew requested a review from olavloite October 20, 2025 17:08
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 21, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 21, 2025
@olavloite olavloite requested a review from bhatt4982 October 21, 2025 12:34
Copy link
Contributor

@bhatt4982 bhatt4982 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM...

@olavloite olavloite merged commit 42027d5 into googleapis:main Oct 21, 2025
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_multi_foreign_keys Returns Columns in Composite Foreign Key Out of Order

4 participants