fix: reject change requests for dealless orders - #65
Conversation
Sirajmx
left a comment
There was a problem hiding this comment.
Confirmed the fix, and it's correct on its own — verified
test_existing_order_with_null_deal_id_returns_structured_error
passes in isolation. But there's a real interaction with #64 worth flagging before this merges,
since the two of you opened within 10 minutes of each other and neither could have seen the
other's change.#64 makes
idempotency_keya required field onPOST /api/v1/change-requests. Your new test's
payload doesn't include one:json={ "order_id": "ORD-TEST001", "change_type": "impressions", "reason": "Increase campaign reach", },Once #64 is in, that request gets rejected at validation (422) before it ever reaches the
deal_id_requiredcheck this test exists to verify — so the test fails on 422 vs the expected
400. Confirmed this locally, deterministically, merging both onto a common base.Direction: add
"idempotency_key": "idem-null-deal-1"(or any non-empty string) to that one
payload. That's the only call this PR makes to that endpoint, so it's the only place this bites.
Verified the one-line fix locally — full suite green (1498 passed, 0 failed) with both PRs and
#63 combined. Happy to merge right after #64 once this is in; no reason to block on ordering
otherwise.
Summary
Why
Orders created without a deal ID are valid through the public orders endpoint, but requesting a change against one passed null into the ChangeRequest model and raised an uncaught validation error. That surfaced as an unstructured HTTP 500.
The write-side normalization prevents new null records, while the read-side check protects records already stored with the old shape.
Testing
Closes #61