From 527f1809d822410f22a84c49d86038d67bbc1095 Mon Sep 17 00:00:00 2001 From: Sakthivel Subramanian Date: Mon, 27 Jul 2026 14:09:54 +0000 Subject: [PATCH] fix(sqlalchemy-spanner): register TOKENLIST in _type_map for reflection Table reflection raises KeyError: 'TOKENLIST' whenever a table containing a TOKENLIST column is reflected. Fixes this issue by registering "TOKENLIST": types.String in _type_map in google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py. --- .../sqlalchemy_spanner/sqlalchemy_spanner.py | 1 + .../tests/mockserver_tests/test_tokenlist.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 packages/sqlalchemy-spanner/tests/mockserver_tests/test_tokenlist.py diff --git a/packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py b/packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py index 2e3190f6e5c9..1a303e630d41 100644 --- a/packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py +++ b/packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py @@ -120,6 +120,7 @@ def process(value): "TIMESTAMP": types.TIMESTAMP, "ARRAY": types.ARRAY, "JSON": types.JSON, + "TOKENLIST": types.String, } diff --git a/packages/sqlalchemy-spanner/tests/mockserver_tests/test_tokenlist.py b/packages/sqlalchemy-spanner/tests/mockserver_tests/test_tokenlist.py new file mode 100644 index 000000000000..fa56f74e4826 --- /dev/null +++ b/packages/sqlalchemy-spanner/tests/mockserver_tests/test_tokenlist.py @@ -0,0 +1,26 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from sqlalchemy import types +from sqlalchemy.testing import eq_, fixtures +from google.cloud.sqlalchemy_spanner.sqlalchemy_spanner import _type_map, SpannerDialect + + +class TokenlistTest(fixtures.TestBase): + def test_tokenlist_reflection_type_mapping(self): + """Test mockserver reflection mapping for TOKENLIST columns.""" + dialect = SpannerDialect() + eq_(_type_map.get("TOKENLIST"), types.String) + col_type = dialect._designate_type("TOKENLIST") + eq_(col_type, types.String)