Skip to content

fix: report event batch serialization failures - #78

Open
Shubham-Padkonde wants to merge 1 commit into
amplitude:mainfrom
Shubham-Padkonde:fix/report-event-serialization-errors
Open

Shubham-Padkonde wants to merge 1 commit into
amplitude:mainfrom
Shubham-Padkonde:fix/report-event-serialization-errors

Conversation

@Shubham-Padkonde

@Shubham-Padkonde Shubham-Padkonde commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

Addresses the missing error notification in #59. When event properties added after construction cannot be serialized (for example, a datetime added by enrichment), the worker raises inside an unobserved background future. The batch is not sent, but neither the configured logger nor callbacks receive the failure.

Catch JSON serialization TypeError/ValueError at the send boundary, log the failure, and notify client/event callbacks for the unsent batch with code 400 and the serialization error. Re-raise the original exception so callers that await a flush future retain the existing error behavior. The batch is not retried and no HTTP request is made.

This does not change constructor property validation or convert unsupported values automatically. On current main, invalid properties passed directly to the constructor are filtered; the regressions exercise properties modified afterward.

Validation

All 117 tests pass on Windows/Python 3.13 and Linux/Python 3.12 using python -m unittest discover -s ./src -p 'test_*.py'. Three regression cases fail before the change because no error is logged. Coverage includes datetime/bytes payload failures, client and event callbacks, a mixed batch, no HTTP request, and preservation of the flush future's exception. No live Amplitude events were sent.

Checklist

  • PR title follows the conventional commit format
  • Does your PR have a breaking change?: No intended breaking change; serialization failures now also produce logs and callbacks.

Prepared with Codex assistance for implementation, tests, and validation.


Note

Low Risk
Change is confined to the send path on serialization failure and mainly adds logging and callbacks where failures were previously invisible.

Overview
Fixes silent failures when a batch cannot be JSON-serialized (e.g. a datetime or bytes slipped into event_properties after construction/enrichment). Workers.send now catches TypeError/ValueError from payload building, logs an ERROR, invokes response_processor.callback for every event in the batch with status 400 and a clear message, then re-raises so flush().result() still surfaces the same exception. No HTTP POST is attempted and retries are unchanged.

Adds regression tests covering mixed batches, client/event callbacks, logging, skipped HttpClient.post, and flush future behavior.

Reviewed by Cursor Bugbot for commit 7cc2513. Bugbot is set up for automated code reviews on this repo. Configure here.

This branch has not been deployed

No deployments
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.

1 participant