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:
13
db.py
13
db.py
@@ -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:
|
||||
"""Create a new asset within a transaction."""
|
||||
row = await conn.fetchrow(
|
||||
|
||||
@@ -2194,8 +2194,8 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
|
||||
await db.create_asset_tx(conn, input_asset)
|
||||
|
||||
# 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(output_hash)
|
||||
existing = await db.get_asset_by_name_tx(conn, output_hash)
|
||||
if existing:
|
||||
logger.info(f"record_run: Output {output_hash[:16]}... already exists")
|
||||
return {"asset": existing, "activity": None, "existing": True}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user