fix(classifieds): manual cleanup of related rows before delete
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
SQLAlchemy ORM tries to UPDATE classified_reads.classified_id = NULL before deleting the classifieds row, even though the FK has ON DELETE CASCADE at DB level. The NOT NULL constraint on classified_id then raises IntegrityError. Same pattern as the forum_reply_reads fix from 2026-02. Manually delete reads, interests, questions, attachments before db.delete(classified). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f3a7f86960
commit
a8be6c8d89
@ -409,6 +409,14 @@ def delete(classified_id):
|
|||||||
if not classified:
|
if not classified:
|
||||||
return jsonify({'success': False, 'error': 'Ogłoszenie nie istnieje'}), 404
|
return jsonify({'success': False, 'error': 'Ogłoszenie nie istnieje'}), 404
|
||||||
|
|
||||||
|
# SQLAlchemy ORM doesn't honor DB-level CASCADE — it tries to UPDATE
|
||||||
|
# FK to NULL on related rows first, which fails on NOT NULL columns.
|
||||||
|
# Same pattern as forum reply delete fix. Wipe related rows first.
|
||||||
|
db.query(ClassifiedRead).filter(ClassifiedRead.classified_id == classified.id).delete(synchronize_session=False)
|
||||||
|
db.query(ClassifiedInterest).filter(ClassifiedInterest.classified_id == classified.id).delete(synchronize_session=False)
|
||||||
|
db.query(ClassifiedQuestion).filter(ClassifiedQuestion.classified_id == classified.id).delete(synchronize_session=False)
|
||||||
|
db.query(ClassifiedAttachment).filter(ClassifiedAttachment.classified_id == classified.id).delete(synchronize_session=False)
|
||||||
|
|
||||||
db.delete(classified)
|
db.delete(classified)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user