fix(sqs): dead_letter never worked — receive() did not retain message bodies#11
Merged
abhi-bhat-lyzr merged 1 commit intoJun 12, 2026
Conversation
… bodies The SQS dead_letter() emulation reads the original message body from self._pending, but receive() never populated it, so every dead_letter() call raised 'No pending message' regardless of the handle. The missing DLQ_NAME test constant masked this: the fixture errored at setup before any dead-letter test could run (and none existed). - receive(): retain receipt_handle -> raw body in _pending - nack(): drop the pending entry (handle goes stale on redelivery; the redelivered message stores a fresh one) - close()/purge(): clear the pending map - tests: define DLQ_NAME; add SQS coverage via moto (dead-letter moves the message to the DLQ with the DeadLetterReason attribute and deletes it from the source, unknown handle raises, no-RedrivePolicy/no-dlq_url raises, explicit dlq_url path, nack-then-dead-letter, get_queue_depth) and Azure mock coverage (dead_letter_message call + receiver release, unknown handle, get_queue_depth via the management client) 195 passed (was 179 passed + 7 fixture errors)
|
bhat-abhishek
approved these changes
Jun 12, 2026
abhi-bhat-lyzr
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes the 7 test-setup errors on
main(NameError: DLQ_NAME is not defined) — and the real bug they were masking.The bug
The new SQS
dead_letter()emulation reads the original message body fromself._pending(documented as "retained between receive() and delete()"), butreceive()never stored anything there. Everydead_letter()call on SQS raisedNo pending message for receipt handleunconditionally. It shipped untested: the fixture was updated to wire a RedrivePolicy for dead-letter tests, but theDLQ_NAMEconstant was missing, so the fixture errored at setup — and no dead-letter tests existed anyway. (The Azure implementation was already correct.)Changes
receive()retainsreceipt_handle → raw bodyin_pendingsodead_letter()can forward the original payload to the DLQnack()drops the pending entry (the handle goes stale on redelivery; the redelivered message stores a fresh one)close()/purge()clear the pending map (no leak across lifecycle events)DLQ_NAME; add the missing coverage —DeadLetterReasonmessage attribute and deletes it from the source; unknown handle raises; queue with no RedrivePolicy and nodlq_url=raises a clearMessagingError; explicitdlq_url=constructor path; nack-then-dead-letter works on the fresh handle;get_queue_depth()dead_letter_message(reason=..., error_description=...)called and receiver released; unknown handle raises;get_queue_depth()resolves throughServiceBusAdministrationClientTest plan
pytest tests/— 195 passed, 0 errors (was 179 passed + 7 errors)ruff checkclean on all touched fileslivetests/6/6 against a real moto SQS server + local Redis/Mongo; lyzr-memory's 9-scenario live suite (wheel installed into its venv, real uvicorn boots of both app trees) all green