fix(campaigns): preserve modification-request audit row after test deletion

Approving a remove_test modification request deletes the underlying Test
row, which was cascading through test_id's ON DELETE CASCADE and wiping
out the request row itself before it could be read back. Changed to
ON DELETE SET NULL so the audit record (justification, reviewer,
decision) survives. Adds regression coverage plus double-approve/reject
idempotency tests.
This commit is contained in:
kitos
2026-07-03 10:48:42 +02:00
parent dc5f206bf5
commit 12a5484003
3 changed files with 101 additions and 4 deletions
+6 -2
View File
@@ -259,10 +259,14 @@ class CampaignModificationRequest(Base):
nullable=True,
)
action = Column(String, nullable=False) # add_test, remove_test
# SET NULL (not CASCADE): approving a "remove_test" request deletes the
# underlying Test row (see remove_test_from_campaign), and this request
# row is the audit record of that decision — it must survive the test's
# deletion, not be wiped out along with it.
test_id = Column(
UUID(as_uuid=True),
ForeignKey("tests.id", ondelete="CASCADE"),
nullable=False,
ForeignKey("tests.id", ondelete="SET NULL"),
nullable=True,
)
order_index = Column(Integer, nullable=True)
phase = Column(String, nullable=True)