diff --git a/db.py b/db.py index 35f2441..3bff73c 100644 --- a/db.py +++ b/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( diff --git a/server.py b/server.py index 7df3af4..67d123f 100644 --- a/server.py +++ b/server.py @@ -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}