You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[sqlalchemy-spanner]: _get_table_filter_query([]) generates invalid SQL '() AND ' when filter_names is empty #18838
I determined this is the correct repository in which to report this bug.
Summary of the issue
When filter_names is an empty collection ([] or ()), SpannerDialect._get_table_filter_query(filter_names, ...) returns "() AND ", causing get_multi_columns, get_multi_pk_constraint, get_multi_foreign_keys, and get_multi_indexes to execute invalid SQL (WHERE () AND ...).
Environment details
OS: Linux
Python version: 3.13
sqlalchemy-spanner version: 1.17.2 (also reproduced on main / 1.20.1 at eb8a76628adf10093959600071a18f50285c2ecf)
def_get_table_filter_query(
self, filter_names, info_schema_table, append_query=False
):
table_filter_query=""iffilter_namesisnotNone:
fortable_nameinfilter_names:
query=f"{info_schema_table}.table_name = '{table_name}'"iftable_filter_query!="":
table_filter_query=table_filter_query+" OR "+queryelse:
table_filter_query=querytable_filter_query="("+table_filter_query+") "ifappend_query:
table_filter_query=table_filter_query+" AND "returntable_filter_query
When filter_names is [] (not None, which means "reflect all tables", whereas [] means "reflect zero tables"), for table_name in filter_names: does not execute, and _get_table_filter_query([], "col", append_query=True) returns "() AND ".
In contrast, SQLAlchemy's get_multi_* contract returns {} when filter_names is an empty collection (e.g., when reflecting a schema with no matching tables).
Suggested fix
Either short-circuit and return {} in get_multi_* when filter_names is not None and not filter_names, or emit "FALSE " / "FALSE AND " in _get_table_filter_query when filter_names is empty (or bind @filter_names with IN UNNEST(@filter_names) as in #18205).
Activity