Mushari440 commited on
Commit
acb610f
·
verified ·
1 Parent(s): 3e0ad10

fix: 500 on delete/rerun — _list_requests never returned _path

Browse files

The Space's _list_requests() returns the parsed request JSON only; unlike the worker's list_requests() it never attached the file path. model_delete() and model_rerun() both did r['_path'], so every call raised KeyError -> 500.

It now carries _path (which cannot be reconstructed reliably, since the filename encodes precision and weight_type as submitted), and both endpoints guard against its absence instead of throwing. /api/manage builds its rows explicitly, so the path is not exposed to the browser.

Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -155,6 +155,10 @@ def _list_requests():
155
  except (requests.RequestException, ValueError):
156
  continue
157
  if isinstance(data, dict) and "model" in data:
 
 
 
 
158
  out.append(data)
159
  return out
160
 
@@ -296,7 +300,7 @@ def model_delete(request: Request, body: ModelRef):
296
  api = HfApi(token=HF_TOKEN)
297
  removed = []
298
  for r in _list_requests():
299
- if r.get("model") == model:
300
  try:
301
  api.delete_file(path_in_repo=r["_path"], repo_id=REQUESTS_REPO,
302
  repo_type="dataset",
@@ -332,6 +336,8 @@ def model_rerun(request: Request, body: ModelRef):
332
  break
333
  if not hit:
334
  raise HTTPException(404, f"{model} is not in the queue.")
 
 
335
  payload = {k: v for k, v in hit.items() if k != "_path"}
336
  payload["status"] = "RERUN"
337
  api.upload_file(
 
155
  except (requests.RequestException, ValueError):
156
  continue
157
  if isinstance(data, dict) and "model" in data:
158
+ # Carry the repo path: the manage endpoints need it to delete or
159
+ # rewrite the exact file, and it cannot be reconstructed reliably
160
+ # (the filename encodes precision/weight_type as submitted).
161
+ data["_path"] = path
162
  out.append(data)
163
  return out
164
 
 
300
  api = HfApi(token=HF_TOKEN)
301
  removed = []
302
  for r in _list_requests():
303
+ if r.get("model") == model and r.get("_path"):
304
  try:
305
  api.delete_file(path_in_repo=r["_path"], repo_id=REQUESTS_REPO,
306
  repo_type="dataset",
 
336
  break
337
  if not hit:
338
  raise HTTPException(404, f"{model} is not in the queue.")
339
+ if not hit.get("_path"):
340
+ raise HTTPException(500, "Could not resolve the request file path.")
341
  payload = {k: v for k, v in hit.items() if k != "_path"}
342
  payload["status"] = "RERUN"
343
  api.upload_file(