Seth commited on
Commit
ae29cd9
·
1 Parent(s): 059e4b7
Files changed (1) hide show
  1. backend/app/main.py +43 -7
backend/app/main.py CHANGED
@@ -182,9 +182,10 @@ async def generate_ai_content(request: AIContentRequest, db: Session = Depends(g
182
  async def get_asset_status(asset_id, db: Session = Depends(get_db)):
183
  """Get the analysis status of an asset"""
184
  try:
185
- # Convert asset_id to int (handle large numbers from CockroachDB)
186
  try:
187
  asset_id = int(asset_id)
 
188
  except (ValueError, TypeError):
189
  raise HTTPException(status_code=400, detail=f"Invalid asset ID: {asset_id}")
190
 
@@ -209,25 +210,56 @@ async def get_asset_status(asset_id, db: Session = Depends(get_db)):
209
 
210
  # Build query based on column existence
211
  try:
 
212
  if has_extracted_content:
213
  cursor.execute("""
214
  SELECT id, name, analysis_status, analyzed_at, extracted_content
215
  FROM assets
216
- WHERE id = %s
217
  """, (asset_id,))
218
  else:
219
  cursor.execute("""
220
  SELECT id, name, analysis_status, analyzed_at
221
  FROM assets
222
- WHERE id = %s
223
  """, (asset_id,))
224
  except Exception as query_error:
225
  print(f"Query error for asset_id {asset_id}: {query_error}")
226
- cursor.close()
227
- conn.close()
228
- raise HTTPException(status_code=500, detail=f"Query failed: {str(query_error)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
  row = cursor.fetchone()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  cursor.close()
232
  conn.close()
233
 
@@ -439,7 +471,9 @@ async def upload_asset(
439
  cursor.close()
440
  conn.close()
441
  if row:
 
442
  db_asset.id = row[0]
 
443
  if hasattr(db_asset, 'created_at') and row[1]:
444
  db_asset.created_at = row[1]
445
  except Exception as psycopg2_error:
@@ -476,8 +510,10 @@ async def upload_asset(
476
  row = cursor.fetchone()
477
  conn.commit()
478
  if row:
479
- db_asset.id = int(row[0]) # Ensure ID is int
 
480
  db_asset.created_at = row[1]
 
481
  cursor.close()
482
  conn.close()
483
  except Exception as psycopg2_error:
 
182
  async def get_asset_status(asset_id, db: Session = Depends(get_db)):
183
  """Get the analysis status of an asset"""
184
  try:
185
+ # Convert asset_id to int (Python int can handle arbitrarily large integers)
186
  try:
187
  asset_id = int(asset_id)
188
+ print(f"Status check for asset_id: {asset_id} (type: {type(asset_id).__name__})")
189
  except (ValueError, TypeError):
190
  raise HTTPException(status_code=400, detail=f"Invalid asset ID: {asset_id}")
191
 
 
210
 
211
  # Build query based on column existence
212
  try:
213
+ # Try querying with explicit bigint cast to handle large IDs
214
  if has_extracted_content:
215
  cursor.execute("""
216
  SELECT id, name, analysis_status, analyzed_at, extracted_content
217
  FROM assets
218
+ WHERE id = %s::bigint
219
  """, (asset_id,))
220
  else:
221
  cursor.execute("""
222
  SELECT id, name, analysis_status, analyzed_at
223
  FROM assets
224
+ WHERE id = %s::bigint
225
  """, (asset_id,))
226
  except Exception as query_error:
227
  print(f"Query error for asset_id {asset_id}: {query_error}")
228
+ # Try without cast as fallback
229
+ try:
230
+ if has_extracted_content:
231
+ cursor.execute("""
232
+ SELECT id, name, analysis_status, analyzed_at, extracted_content
233
+ FROM assets
234
+ WHERE id = %s
235
+ """, (asset_id,))
236
+ else:
237
+ cursor.execute("""
238
+ SELECT id, name, analysis_status, analyzed_at
239
+ FROM assets
240
+ WHERE id = %s
241
+ """, (asset_id,))
242
+ except Exception as fallback_error:
243
+ cursor.close()
244
+ conn.close()
245
+ raise HTTPException(status_code=500, detail=f"Query failed: {str(fallback_error)}")
246
 
247
  row = cursor.fetchone()
248
+
249
+ # Debug: If not found, check if asset exists with different query
250
+ if not row:
251
+ try:
252
+ cursor.execute("SELECT COUNT(*) FROM assets WHERE id = %s", (asset_id,))
253
+ count = cursor.fetchone()[0]
254
+ print(f"Debug: Asset ID {asset_id} (type: {type(asset_id)}) - Count: {count}")
255
+
256
+ # Also check recent assets to see what IDs look like
257
+ cursor.execute("SELECT id, name FROM assets ORDER BY id DESC LIMIT 5")
258
+ recent = cursor.fetchall()
259
+ print(f"Debug: Recent asset IDs: {[r[0] for r in recent]}")
260
+ except Exception as debug_error:
261
+ print(f"Debug query error: {debug_error}")
262
+
263
  cursor.close()
264
  conn.close()
265
 
 
471
  cursor.close()
472
  conn.close()
473
  if row:
474
+ # Keep ID as returned from database (CockroachDB uses bigint)
475
  db_asset.id = row[0]
476
+ print(f"✓ Asset created with ID: {db_asset.id} (type: {type(db_asset.id).__name__})")
477
  if hasattr(db_asset, 'created_at') and row[1]:
478
  db_asset.created_at = row[1]
479
  except Exception as psycopg2_error:
 
510
  row = cursor.fetchone()
511
  conn.commit()
512
  if row:
513
+ # Keep ID as returned from database (CockroachDB uses bigint)
514
+ db_asset.id = row[0]
515
  db_asset.created_at = row[1]
516
+ print(f"✓ Asset created with ID: {db_asset.id} (type: {type(db_asset.id).__name__})")
517
  cursor.close()
518
  conn.close()
519
  except Exception as psycopg2_error: