Skip to content

Commit ed70579

Browse files
committed
Update cassandra_compat.py
1 parent 644ef53 commit ed70579

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

r2/r2/lib/db/cassandra_compat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ def get(self, key: str, columns: Optional[Iterable[str]] = None,
350350
return od
351351

352352
def insert(self, key: str, columns: Dict[str, object], ttl: Optional[int] = None):
353+
# Coerce key to str — UuidThing._id is a UUID object but the table key column is text.
354+
key = str(key)
353355
# serialize values and attach a write timestamp (microseconds)
354356
now_us = int(time.time() * 1e6)
355357
# Ensure map keys are text (CQL map<text, blob>)
@@ -490,6 +492,8 @@ def insert(self, key_or_cf, columns_or_key, ttl_or_columns=None, ttl=None):
490492
now_us = int(time.time() * 1e6)
491493
# ensure map keys are strings for CQL map<text, blob>
492494
ser = {str(k): pickle.dumps((v, now_us)) for k, v in columns.items()}
495+
# Coerce key to str — UuidThing._id is a UUID object but the table key column is text.
496+
key = str(key)
493497
if ttl:
494498
cql = "UPDATE %s.%s USING TTL %d SET columns = columns + %%s WHERE key = %%s" % (cf.keyspace, cf.table, int(ttl))
495499
params = (ser, key)
@@ -499,6 +503,7 @@ def insert(self, key_or_cf, columns_or_key, ttl_or_columns=None, ttl=None):
499503
self._ops.append(("insert", cql, params))
500504

501505
def remove(self, cf, key, columns=None, timestamp=None):
506+
key = str(key)
502507
if columns is None:
503508
cql = "DELETE FROM %s.%s WHERE key = %%s" % (cf.keyspace, cf.table)
504509
params = (key,)

0 commit comments

Comments
 (0)