Skip to content

Commit b60699e

Browse files
fix(sqlalchemy-spanner): default supports_native_uuid to False for legacy Uuid compatibility
1 parent 681f3de commit b60699e

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ def visit_uuid(self, type_, **kw):
778778
if not type_.native_uuid or not self.dialect.supports_native_uuid:
779779
return self.visit_CHAR(types.CHAR(36), **kw)
780780
else:
781-
return "UUID"
781+
return self.visit_UUID(type_, **kw)
782782

783783
def visit_INTEGER(self, type_, **kw):
784784
return "INT64"
@@ -862,7 +862,7 @@ class SpannerDialect(DefaultDialect):
862862
supports_identity_columns = True
863863
supports_native_boolean = True
864864
supports_native_decimal = True
865-
supports_native_uuid = True
865+
supports_native_uuid = False
866866
supports_statement_cache = True
867867
# Spanner uses protos for enums. Creating a column like
868868
# Column("an_enum", Enum("A", "B", "C")) will result in a String

packages/sqlalchemy-spanner/tests/mockserver_tests/test_uuid.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,40 @@ def test_uuid_type_mapping(self):
3535
def test_uuid_designate_type(self):
3636
"""Test reflecting UUID type string returns types.UUID."""
3737
dialect = SpannerDialect()
38-
assert dialect.supports_native_uuid is True
38+
assert dialect.supports_native_uuid is False
3939
col_type = dialect._designate_type("UUID")
4040
eq_(col_type, types.UUID)
4141

4242
def test_uuid_ddl_compilation_default(self):
43-
"""Test DDL compilation emits UUID type by default when supports_native_uuid
44-
is True.
43+
"""Test DDL compilation: types.Uuid emits STRING(36) by default and
44+
types.UUID emits UUID by default.
4545
"""
4646
dialect = SpannerDialect()
4747
metadata = MetaData()
4848
table = Table(
4949
"test_uuid_table",
5050
metadata,
51-
Column("user_id", types.Uuid, primary_key=True),
51+
Column("legacy_id", types.Uuid, primary_key=True),
52+
Column("native_id", types.UUID),
5253
)
5354
statement = str(CreateTable(table).compile(dialect=dialect)).strip()
54-
assert "user_id UUID NOT NULL" in statement
55+
assert "legacy_id STRING(36) NOT NULL" in statement
56+
assert "native_id UUID" in statement
5557

56-
def test_uuid_ddl_compilation_native_disabled(self):
57-
"""Test DDL compilation falls back to STRING(36) when supports_native_uuid
58-
is False.
58+
def test_uuid_ddl_compilation_native_enabled(self):
59+
"""Test DDL compilation emits UUID type for types.Uuid when supports_native_uuid
60+
is set to True on dialect.
5961
"""
6062
dialect = SpannerDialect()
61-
dialect.supports_native_uuid = False
63+
dialect.supports_native_uuid = True
6264
metadata = MetaData()
6365
table = Table(
6466
"test_uuid_table",
6567
metadata,
6668
Column("user_id", types.Uuid, primary_key=True),
6769
)
6870
statement = str(CreateTable(table).compile(dialect=dialect)).strip()
69-
assert "user_id STRING(36) NOT NULL" in statement
71+
assert "user_id UUID NOT NULL" in statement
7072

7173
def test_uuid_python_conversion_legacy(self):
7274
"""Test that types.Uuid automatically converts uuid.UUID to/from str

0 commit comments

Comments
 (0)