From 4c4dd3566b0c7ab67813b8dbbe775ec42a04fddf Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Thu, 1 Feb 2024 11:43:17 -0500 Subject: [PATCH] cache fixes * make sure Item.updated is a datetime object * remove id column when creating Item objects in SqlCache --- relay/cache.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/relay/cache.py b/relay/cache.py index 9763e8c..97aff14 100644 --- a/relay/cache.py +++ b/relay/cache.py @@ -69,6 +69,7 @@ class Item: def from_data(cls: type[Item], *args) -> Item: data = cls(*args) data.value = deserialize_value(data.value, data.value_type) + data.updated = datetime.fromtimestamp(data.updated, tz = timezone.utc) return data @@ -153,6 +154,7 @@ class SqlCache(Cache): if not (row := cur.one()): raise KeyError(f'{namespace}:{key}') + row.pop('id', None) return Item.from_data(*tuple(row.values())) @@ -178,7 +180,9 @@ class SqlCache(Cache): } with self._db.connection() as conn: - for row in conn.exec_statement('set-cache-item', params): + with conn.exec_statement('set-cache-item', params) as conn: + row = conn.one() + row.pop('id', None) return Item.from_data(*tuple(row.values()))