Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit db654f3

Browse files
harshachintasinhasubham
authored andcommitted
chore: add uuid support
Signed-off-by: Sri Harsha CH <sriharshach@google.com>
1 parent 3d3cea0 commit db654f3

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

google/cloud/spanner_v1/_helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import base64
2222
import threading
2323
import logging
24+
import uuid
2425

2526
from google.protobuf.struct_pb2 import ListValue
2627
from google.protobuf.struct_pb2 import Value
@@ -298,6 +299,8 @@ def _make_value_pb(value):
298299
return Value(string_value=base64.b64encode(value))
299300
if isinstance(value, Interval):
300301
return Value(string_value=str(value))
302+
if isinstance(value, uuid.UUID):
303+
return Value(string_value=str(value))
301304

302305
raise ValueError("Unknown type: %s" % (value,))
303306

@@ -399,6 +402,8 @@ def _get_type_decoder(field_type, field_name, column_info=None):
399402
return _parse_numeric
400403
elif type_code == TypeCode.JSON:
401404
return _parse_json
405+
elif type_code == TypeCode.UUID:
406+
return _parse_uuid
402407
elif type_code == TypeCode.PROTO:
403408
return lambda value_pb: _parse_proto(value_pb, column_info, field_name)
404409
elif type_code == TypeCode.ENUM:
@@ -481,6 +486,10 @@ def _parse_json(value_pb):
481486
return JsonObject.from_str(value_pb.string_value)
482487

483488

489+
def _parse_uuid(value_pb):
490+
return uuid.UUID(value_pb.string_value)
491+
492+
484493
def _parse_proto(value_pb, column_info, field_name):
485494
bytes_value = base64.b64decode(value_pb.string_value)
486495
if column_info is not None and column_info.get(field_name) is not None:

0 commit comments

Comments
 (0)