Repository navigation
Description
Hi there! Cloud Spanner added the native UUID column type in January 2026, but the sqlalchemy-spanner dialect does not recognize it yet. There is no entry in _type_map / _type_map_inv and no visit_UUID method in SpannerTypeCompiler.
In practice this means:
Column(sqlalchemy.Uuid)emitsVARCHARDDL instead ofUUID- Reading a
UUIDcolumn withsqlalchemy.Uuidfails withAttributeError: 'str' object has no attribute 'hex'because the driver returns strings but the SQLAlchemyUuidtype expectsuuid.UUIDobjects GENERATE_UUID()as column default is not recognized
Desired Code Experience
from sqlalchemy import Column, Uuid, create_engine
from sqlalchemy.orm import DeclarativeBase
import uuid
class Base(DeclarativeBase):
pass
class MyTable(Base):
__tablename__ = "my_table"
id = Column(Uuid, primary_key=True, default=uuid.uuid4)
ref_id = Column(Uuid, nullable=True)This should:
- Emit
UUIDin DDL (notVARCHAR) - Accept
uuid.UUIDobjects on writes, converting to string for the Spanner API - Return
uuid.UUIDobjects on reads, converting from string
Expected Results
CREATE TABLE my_table (
id UUID NOT NULL,
ref_id UUID,
) PRIMARY KEY (id)row = session.get(MyTable, some_uuid)
assert isinstance(row.id, uuid.UUID)API Client Information
sqlalchemy-spanner 1.14.0 (also verified against main branch / 1.17.2, neither has UUID support)
Use Case
We are building an Event Store on Cloud Spanner using UUID v4 as surrogate keys for aggregates and event IDs. The native UUID type stores 16 bytes internally (vs 36 bytes for STRING), provides built-in validation, and enables GENERATE_UUID() as server-side default. We currently work around this with a TypeDecorator wrapping String, but this prevents proper DDL emission and adds unnecessary indirection.
Additional Context
- Spanner UUID docs: https://docs.cloud.google.com/spanner/docs/schema-design#uuid_primary_key
_type_mapinsqlalchemy_spanner.pyneeds a"UUID": types.Uuidentry_type_map_invneeds atypes.Uuid: "UUID"entrySpannerTypeCompilerneeds avisit_UUIDmethod returning"UUID"
Activity
cdco-busunkim commentedon Jun 26, 2026
@chalmerlowe @olavloite Are there any plans to do add native UUID type support?
sakthivelmanii commentedon Sep 6, 2026
[Close](#17913)