Fix UUID parsing errors for content-addressable activity IDs
Activity IDs are now VARCHAR(64) content hashes, not UUIDs. Removed all UUID() conversions and updated SQL casts from uuid[] to text[]. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
18
db.py
18
db.py
@@ -9,7 +9,6 @@ import os
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from contextlib import asynccontextmanager
|
||||
from uuid import UUID
|
||||
|
||||
import asyncpg
|
||||
|
||||
@@ -431,7 +430,7 @@ async def get_activity(activity_id: str) -> Optional[dict]:
|
||||
row = await conn.fetchrow(
|
||||
"""SELECT activity_id, activity_type, actor_id, object_data, published, signature
|
||||
FROM activities WHERE activity_id = $1""",
|
||||
UUID(activity_id)
|
||||
activity_id
|
||||
)
|
||||
if row:
|
||||
return _parse_activity_row(row)
|
||||
@@ -491,7 +490,7 @@ async def create_activity(activity: dict) -> dict:
|
||||
"""INSERT INTO activities (activity_id, activity_type, actor_id, object_data, published, signature)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING *""",
|
||||
UUID(activity["activity_id"]),
|
||||
activity["activity_id"],
|
||||
activity["activity_type"],
|
||||
activity["actor_id"],
|
||||
json.dumps(activity["object_data"]),
|
||||
@@ -510,9 +509,6 @@ async def count_activities() -> int:
|
||||
def _parse_activity_row(row) -> dict:
|
||||
"""Parse a database row into an activity dict, handling JSONB fields."""
|
||||
activity = dict(row)
|
||||
# Convert UUID to string
|
||||
if activity.get("activity_id"):
|
||||
activity["activity_id"] = str(activity["activity_id"])
|
||||
# Convert datetime to ISO string
|
||||
if activity.get("published"):
|
||||
activity["published"] = activity["published"].isoformat()
|
||||
@@ -534,7 +530,7 @@ async def create_activity_tx(conn, activity: dict) -> dict:
|
||||
"""INSERT INTO activities (activity_id, activity_type, actor_id, object_data, published, signature)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING *""",
|
||||
UUID(activity["activity_id"]),
|
||||
activity["activity_id"],
|
||||
activity["activity_type"],
|
||||
activity["actor_id"],
|
||||
json.dumps(activity["object_data"]),
|
||||
@@ -624,8 +620,8 @@ async def create_anchor(anchor: dict) -> dict:
|
||||
anchor.get("tree_ipfs_cid"),
|
||||
anchor.get("ots_proof_cid"),
|
||||
anchor["activity_count"],
|
||||
UUID(anchor["first_activity_id"]) if anchor.get("first_activity_id") else None,
|
||||
UUID(anchor["last_activity_id"]) if anchor.get("last_activity_id") else None
|
||||
anchor.get("first_activity_id"),
|
||||
anchor.get("last_activity_id")
|
||||
)
|
||||
return dict(row)
|
||||
|
||||
@@ -635,9 +631,9 @@ async def mark_activities_anchored(activity_ids: list[str], merkle_root: str) ->
|
||||
async with get_connection() as conn:
|
||||
result = await conn.execute(
|
||||
"""UPDATE activities SET anchor_root = $1
|
||||
WHERE activity_id = ANY($2::uuid[])""",
|
||||
WHERE activity_id = ANY($2::text[])""",
|
||||
merkle_root,
|
||||
[UUID(aid) for aid in activity_ids]
|
||||
activity_ids
|
||||
)
|
||||
# Returns "UPDATE N"
|
||||
return int(result.split()[1]) if result else 0
|
||||
|
||||
Reference in New Issue
Block a user