Skip to content

Commit 0a2a1c9

Browse files
handle replaying uuid properly
1 parent be8de29 commit 0a2a1c9

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

drift/instrumentation/utils/psycopg_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import base64
66
import datetime as dt
7+
import uuid
78
from typing import Any
89

910

@@ -13,6 +14,7 @@ def deserialize_db_value(val: Any) -> Any:
1314
During recording, database values are serialized for JSON storage:
1415
- datetime objects -> ISO format strings
1516
- bytes/memoryview -> {"__bytes__": "<base64_encoded_data>"}
17+
- uuid.UUID -> {"__uuid__": "<uuid_string>"}
1618
1719
During replay, we need to convert them back to their original types so that
1820
application code (Flask/Django) handles them the same way.
@@ -28,6 +30,9 @@ def deserialize_db_value(val: Any) -> Any:
2830
if "__bytes__" in val and len(val) == 1:
2931
# Decode base64 back to bytes
3032
return base64.b64decode(val["__bytes__"])
33+
# Check for UUID tagged structure
34+
if "__uuid__" in val and len(val) == 1:
35+
return uuid.UUID(val["__uuid__"])
3136
# Recursively deserialize dict values
3237
return {k: deserialize_db_value(v) for k, v in val.items()}
3338
elif isinstance(val, str):

drift/instrumentation/utils/serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def serialize_value(val: Any) -> Any:
4343
if isinstance(val, (datetime.datetime, datetime.date, datetime.time)):
4444
return val.isoformat()
4545
elif isinstance(val, uuid.UUID):
46-
return str(val)
46+
return {"__uuid__": str(val)}
4747
elif isinstance(val, memoryview):
4848
# Convert memoryview to bytes first, then serialize
4949
return _serialize_bytes(bytes(val))

0 commit comments

Comments
 (0)