Repository navigation
fix(sqlalchemy-spanner): handle empty filter_names in multi-table reflection - #18843
Open
rocksnow1942 wants to merge 1 commit into
Open
rocksnow1942 wants to merge 1 commit into
rocksnow1942 wants to merge 1 commit into
Conversation
…lection An empty filter_names rendered "()" in the WHERE clause of the get_multi_*() queries, so MetaData.reflect() failed with a syntax error when it had no tables to load, e.g. on an empty database. Render an always-false condition instead, so an empty filter_names returns no tables. Fixes googleapis#18838
Contributor
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where an empty filter_names argument in _get_table_filter_query would generate invalid SQL (()). The fix ensures that an empty filter renders a condition that is always false ((FALSE)), selecting no tables. Additionally, comprehensive unit and integration tests have been added to verify this behavior during metadata reflection and multi-column retrieval. There are no review comments, and I have no additional feedback to provide.
rocksnow1942
marked this pull request as ready for review
October 24, 2026 09:52
This branch has not been deployed
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.
_get_table_filter_query()rendered()for an emptyfilter_names, so theget_multi_*()queries failed with400 Syntax error: Unexpected ")". SQLAlchemy passes an emptyfilter_nameswhen there's nothing to reflect, so these failed:MetaData().reflect(engine)on a database without tablesMetaData.reflect()withonly=[], or when all the tables are already in theMetaDataget_multi_*()methodsThis PR renders
(FALSE)instead, so an emptyfilter_namesreturns no tables.SQLAlchemy doesn't define what an empty
filter_namesmeans. Its built-in dialects checkif filter_names:, so they treat[]likeNoneand return all tables, while theIN UNNEST(@filter_names)filter of #18205 returns none. This PR returns none, which avoids reflecting the whole schema when there's nothing to load. I'm happy to switch to the other behavior if you prefer.Tested with the unit and mockserver tests and the compliance suite against the emulator.
Fixes #18838