Add unique constraint to prevent duplicate (author, chapter, page) submissions
Adds a PostgreSQL partial unique index on (author, chapter, page) where all three fields are non-null, and returns HTTP 409 when a duplicate is detected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -675,6 +675,12 @@ async def commit_job(
|
||||
os.remove(image_path)
|
||||
except Exception:
|
||||
pass
|
||||
# Unique constraint violation (author + chapter + page already exists)
|
||||
if getattr(exc, 'pgcode', None) == '23505':
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="A job with this Author, Chapter, and Page already exists."
|
||||
)
|
||||
print(f"Job commit DB error: {exc}")
|
||||
raise HTTPException(status_code=500, detail="Failed to save job to database.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user