From 12de570a00eaadb47d9e16f9815a5144ea455544 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Tue, 7 Jul 2026 10:56:44 -0600 Subject: [PATCH] Add workarounds in env.py --- src/migrations/env.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/migrations/env.py b/src/migrations/env.py index 8069719..f96715b 100644 --- a/src/migrations/env.py +++ b/src/migrations/env.py @@ -9,6 +9,37 @@ from src.models import Base +# --- START sqlalchemy-spanner workarounds --- +from google.cloud.sqlalchemy_spanner.sqlalchemy_spanner import SpannerDialect + + +original_get_multi_pk = SpannerDialect.get_multi_pk_constraint +original__get_table_filter_query = SpannerDialect._get_table_filter_query + + +def patched_get_multi_pk_constraint(self, connection, **kw): + """Intercepts the PK constraint dictionary to inject the missing 'name' key.""" + result = original_get_multi_pk(self, connection, **kw) + for pk_dict in result.values(): + if "name" not in pk_dict: + pk_dict["name"] = None + return result + + +def patched__get_table_filter_query( + self, filter_names, *args, **kwargs +): + """Pass None for filter names instead of empty list to avoid invalid SQL generation""" + if len(filter_names) == 0: + filter_names = None + + return original__get_table_filter_query(self, filter_names, *args, **kwargs) + + +SpannerDialect._get_table_filter_query = patched__get_table_filter_query +SpannerDialect.get_multi_pk_constraint = patched_get_multi_pk_constraint +# --- END of workarounds --- + # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config