Fix NoneType subscript error in record_run

- Add get_asset_by_name_tx for transaction-aware asset lookup
- Use transaction connection instead of separate connection
- Prevents race condition where asset might not be visible

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-10 15:07:42 +00:00
parent 59484936fd
commit 678d0e0ea3
2 changed files with 15 additions and 2 deletions

13
db.py
View File

@@ -464,6 +464,19 @@ async def asset_exists_by_name_tx(conn, name: str) -> bool:
) )
async def get_asset_by_name_tx(conn, name: str) -> Optional[dict]:
"""Get asset by name within a transaction."""
row = await conn.fetchrow(
"""SELECT name, content_hash, ipfs_cid, asset_type, tags, metadata, url,
provenance, description, origin, owner, created_at, updated_at
FROM assets WHERE name = $1""",
name
)
if row:
return _parse_asset_row(row)
return None
async def create_asset_tx(conn, asset: dict) -> dict: async def create_asset_tx(conn, asset: dict) -> dict:
"""Create a new asset within a transaction.""" """Create a new asset within a transaction."""
row = await conn.fetchrow( row = await conn.fetchrow(

View File

@@ -2194,8 +2194,8 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
await db.create_asset_tx(conn, input_asset) await db.create_asset_tx(conn, input_asset)
# Check if output already exists (by content_hash) - return existing if so # Check if output already exists (by content_hash) - return existing if so
if await db.asset_exists_by_name_tx(conn, output_hash): existing = await db.get_asset_by_name_tx(conn, output_hash)
existing = await db.get_asset(output_hash) if existing:
logger.info(f"record_run: Output {output_hash[:16]}... already exists") logger.info(f"record_run: Output {output_hash[:16]}... already exists")
return {"asset": existing, "activity": None, "existing": True} return {"asset": existing, "activity": None, "existing": True}