fix: guard db.close() in add_to_digest_queue with try/finally

This commit is contained in:
pyr0ball 2026-03-20 06:54:50 -07:00
parent a503ecde3b
commit 7993984af9

View file

@ -483,19 +483,20 @@ def list_digest_queue():
@app.post("/api/digest-queue") @app.post("/api/digest-queue")
def add_to_digest_queue(body: DigestQueueBody): def add_to_digest_queue(body: DigestQueueBody):
db = _get_db() db = _get_db()
exists = db.execute( try:
"SELECT 1 FROM job_contacts WHERE id = ?", (body.job_contact_id,) exists = db.execute(
).fetchone() "SELECT 1 FROM job_contacts WHERE id = ?", (body.job_contact_id,)
if not exists: ).fetchone()
if not exists:
raise HTTPException(404, "job_contact_id not found")
result = db.execute(
"INSERT OR IGNORE INTO digest_queue (job_contact_id) VALUES (?)",
(body.job_contact_id,),
)
db.commit()
created = result.rowcount > 0
finally:
db.close() db.close()
raise HTTPException(404, "job_contact_id not found")
result = db.execute(
"INSERT OR IGNORE INTO digest_queue (job_contact_id) VALUES (?)",
(body.job_contact_id,),
)
db.commit()
created = result.rowcount > 0
db.close()
return {"ok": True, "created": created} return {"ok": True, "created": created}