Skip to content

Enhance service bus handling of invalid JSON in receive_message function#4932

Open
JC-wk wants to merge 5 commits into
microsoft:mainfrom
JC-wk:fix-json-decode
Open

Enhance service bus handling of invalid JSON in receive_message function#4932
JC-wk wants to merge 5 commits into
microsoft:mainfrom
JC-wk:fix-json-decode

Conversation

@JC-wk

@JC-wk JC-wk commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

What is being addressed

Service bus will now skip malformed payloads instead of crashing

How is this addressed

Summary of Changes

  1. Bug Fix in runner.py:
    • Caught json.JSONDecodeError when deserializing the Service Bus message payload.
    • Sent the malformed message to the dead-letter queue via await receiver.dead_letter_message(msg, reason="InvalidJSON") to clear it from the queue and aid in troubleshooting.
    • Added a continue statement inside the except block to prevent processing of empty/malformed message structures, avoiding downstream TypeError crashes.
  2. Added Unit Tests in test_runner.py:
    • Added a new unit test test_receive_message_bad_json to simulate receiving a malformed/non-JSON payload, asserting that:
    • The message is successfully sent to the dead-letter queue.
    • The message is not processed or marked complete (i.e. skipped).
  • Updated CHANGELOG.md
  • Increment version

James Chapman added 2 commits June 9, 2026 09:27
@JC-wk JC-wk requested a review from a team as a code owner June 9, 2026 09:33
Copilot AI review requested due to automatic review settings June 9, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the resource processor’s Service Bus session receiver loop to tolerate malformed/non-JSON messages by dead-lettering them and continuing processing, instead of crashing the runner.

Changes:

  • Dead-letter malformed Service Bus messages on json.JSONDecodeError and skip further processing of that message.
  • Add a unit test covering the malformed JSON path in receive_message.
  • Bump resource_processor version and add an Unreleased changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
resource_processor/vmss_porter/runner.py Dead-letters invalid JSON messages and continues the receive loop.
resource_processor/tests_rp/test_runner.py Adds a unit test to verify invalid JSON messages are dead-lettered and not completed.
resource_processor/_version.py Patch version bump.
CHANGELOG.md Adds an Unreleased BUG FIXES entry for the change.

Comment thread resource_processor/vmss_porter/runner.py Outdated
Comment thread resource_processor/tests_rp/test_runner.py Outdated
Comment thread CHANGELOG.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Unit Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 59a309a.

♻️ This comment has been updated with latest results.

@rudolphjacksonm

Copy link
Copy Markdown
Collaborator

/test 59a309a

@github-actions

Copy link
Copy Markdown

🤖 pr-bot 🤖

🏃 Running tests: https://github.com/microsoft/AzureTRE/actions/runs/27306698867 (with refid a20534b2)

(in response to this comment from @rudolphjacksonm)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants