Skip to content

Navigation Menu

Sign in
Sign up

fix(webhooks): send payload as JSON object instead of double-encoded string - #623

Open
MateoLostanlen wants to merge 5 commits into
main from
fix/webhook-double-serialization
Open

fix(webhooks): send payload as JSON object instead of double-encoded string #623
MateoLostanlen wants to merge 5 commits into
main from
fix/webhook-double-serialization

Conversation

@MateoLostanlen

@MateoLostanlen MateoLostanlen commented Jun 11, 2026
edited
Loading

Copy link
Copy Markdown
Member

Bug

dispatch_webhook passed model_dump_json() (a str) to httpx's json=, which JSON-encoded it a second time. Every generic webhook consumer received a double-encoded body: a quoted JSON string like "{\"id\": 123, ...}" instead of the object {"id": 123, ...}, so any parser got a str instead of a dict. Present since the mechanism was introduced (#367).

Why Slack notifications were never affected

The Slack messages we receive go through the dedicated organization.slack_hook path (slack_client.notify, #478), which formats a proper Slack message. The recurring 400 invalid_payload errors in the prod logs came from the same Slack URL being also registered in the generic webhook table, a leftover from before #478 that never worked and only produced log noise. That row has been removed from the prod table.

Why fix the payload anyway

Removing the bad row only stops the log noise: the generic webhook mechanism itself stays broken for its intended use. Any legitimate consumer registered in the webhook table (partner system, internal service expecting the detection JSON) would still receive a double-encoded string. This fixes the mechanism for the next consumer.

Changes

  • Use model_dump(mode="json") and let httpx do the encoding.
  • Log httpx.RequestError (timeouts, connection failures) instead of letting them bubble up, consistent with best-effort dispatch.
  • Add a regression test asserting the dispatched body is a JSON object.

...string
model_dump_json() returns a str, which httpx json= encodes a second
time, so consumers received a quoted JSON string instead of an object
(Slack rejects it with 400 invalid_payload). Use model_dump(mode="json")
and let httpx do the encoding. Also log connection/timeout errors
instead of letting them bubble up to callers.

codecov Bot commented Jun 11, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.68%. Comparing base (3cf4d52) to head (d84fa4f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@
## main #623 +/- ##
==========================================
+ Coverage 90.97% 93.68% +2.71% 
==========================================
 Files 3 59 +56 
 Lines 133 3074 +2941 
==========================================
+ Hits 121 2880 +2759 
- Misses 12 194 +182 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /