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 datetime import datetime, timezone
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
import asyncpg
|
import asyncpg
|
||||||
|
|
||||||
@@ -431,7 +430,7 @@ async def get_activity(activity_id: str) -> Optional[dict]:
|
|||||||
row = await conn.fetchrow(
|
row = await conn.fetchrow(
|
||||||
"""SELECT activity_id, activity_type, actor_id, object_data, published, signature
|
"""SELECT activity_id, activity_type, actor_id, object_data, published, signature
|
||||||
FROM activities WHERE activity_id = $1""",
|
FROM activities WHERE activity_id = $1""",
|
||||||
UUID(activity_id)
|
activity_id
|
||||||
)
|
)
|
||||||
if row:
|
if row:
|
||||||
return _parse_activity_row(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)
|
"""INSERT INTO activities (activity_id, activity_type, actor_id, object_data, published, signature)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING *""",
|
RETURNING *""",
|
||||||
UUID(activity["activity_id"]),
|
activity["activity_id"],
|
||||||
activity["activity_type"],
|
activity["activity_type"],
|
||||||
activity["actor_id"],
|
activity["actor_id"],
|
||||||
json.dumps(activity["object_data"]),
|
json.dumps(activity["object_data"]),
|
||||||
@@ -510,9 +509,6 @@ async def count_activities() -> int:
|
|||||||
def _parse_activity_row(row) -> dict:
|
def _parse_activity_row(row) -> dict:
|
||||||
"""Parse a database row into an activity dict, handling JSONB fields."""
|
"""Parse a database row into an activity dict, handling JSONB fields."""
|
||||||
activity = dict(row)
|
activity = dict(row)
|
||||||
# Convert UUID to string
|
|
||||||
if activity.get("activity_id"):
|
|
||||||
activity["activity_id"] = str(activity["activity_id"])
|
|
||||||
# Convert datetime to ISO string
|
# Convert datetime to ISO string
|
||||||
if activity.get("published"):
|
if activity.get("published"):
|
||||||
activity["published"] = activity["published"].isoformat()
|
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)
|
"""INSERT INTO activities (activity_id, activity_type, actor_id, object_data, published, signature)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING *""",
|
RETURNING *""",
|
||||||
UUID(activity["activity_id"]),
|
activity["activity_id"],
|
||||||
activity["activity_type"],
|
activity["activity_type"],
|
||||||
activity["actor_id"],
|
activity["actor_id"],
|
||||||
json.dumps(activity["object_data"]),
|
json.dumps(activity["object_data"]),
|
||||||
@@ -624,8 +620,8 @@ async def create_anchor(anchor: dict) -> dict:
|
|||||||
anchor.get("tree_ipfs_cid"),
|
anchor.get("tree_ipfs_cid"),
|
||||||
anchor.get("ots_proof_cid"),
|
anchor.get("ots_proof_cid"),
|
||||||
anchor["activity_count"],
|
anchor["activity_count"],
|
||||||
UUID(anchor["first_activity_id"]) if anchor.get("first_activity_id") else None,
|
anchor.get("first_activity_id"),
|
||||||
UUID(anchor["last_activity_id"]) if anchor.get("last_activity_id") else None
|
anchor.get("last_activity_id")
|
||||||
)
|
)
|
||||||
return dict(row)
|
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:
|
async with get_connection() as conn:
|
||||||
result = await conn.execute(
|
result = await conn.execute(
|
||||||
"""UPDATE activities SET anchor_root = $1
|
"""UPDATE activities SET anchor_root = $1
|
||||||
WHERE activity_id = ANY($2::uuid[])""",
|
WHERE activity_id = ANY($2::text[])""",
|
||||||
merkle_root,
|
merkle_root,
|
||||||
[UUID(aid) for aid in activity_ids]
|
activity_ids
|
||||||
)
|
)
|
||||||
# Returns "UPDATE N"
|
# Returns "UPDATE N"
|
||||||
return int(result.split()[1]) if result else 0
|
return int(result.split()[1]) if result else 0
|
||||||
|
|||||||
Reference in New Issue
Block a user