Skip to content

fix: Drop track events with a NaN or infinite metric value - #599

Merged
tanderson-ld merged 1 commit into
launchdarkly:mainfrom
pcbeingused33:fix/track-non-finite-metric
Nov 30, 2026
Merged

tanderson-ld merged 1 commit into
launchdarkly:mainfrom
pcbeingused33:fix/track-non-finite-metric

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions (tested on one Python version only)
  • Sync/async parity: matching changes made to async_* siblings (or N/A)

Related issues

No issue in this repository. Same fix as launchdarkly/go-server-sdk#520 and launchdarkly/ruby-server-sdk#498.

Describe the solution you've provided

track() with a NaN or infinite metric_value puts the value straight into the custom event. The event processor serializes the whole batch with json.dumps, which by default writes the non-standard tokens NaN, Infinity and -Infinity, so the request body for that flush is not valid JSON and the other events in it are at risk too.

LDClient.track and AsyncLDClient.track now check for a non-finite float after the existing context check. In that case they log a warning that names the event and do not record it. Other values behave as before, and data is not inspected. The docstrings mention the new behavior.

New tests cover NaN, +Infinity and -Infinity on both clients. They fail without the change and pass with it. The client, async client and hook tests pass, and mypy, isort and pycodestyle are clean on the changed source files.

Describe alternatives you've considered

  • Sending the event without metricValue: this would silently report a different measurement.
  • Passing allow_nan=False to json.dumps: the whole batch would then fail to serialize.

Additional context

This change was prepared with the assistance of an AI coding agent (Claude Code).


Note

Overview
LDClient.track and AsyncLDClient.track now reject custom events when metric_value is a non-finite float (NaN, ±Infinity): they log a warning naming the event and skip sending, instead of letting those values reach batch JSON serialization (which can emit invalid JSON and jeopardize other events in the same flush). Docstrings describe this behavior.

Parametric tests were added on both sync and async clients to assert no event is recorded and the warning appears for each non-finite metric value.

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 27, 2026 06:54
@tanderson-ld

Copy link
Copy Markdown
Contributor

bugbot review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6298882. Configure here.

@tanderson-ld
tanderson-ld self-requested a review November 30, 2026 14:42
@tanderson-ld
tanderson-ld merged commit 6a0e1bf into launchdarkly:main Nov 30, 2026
19 checks passed
tanderson-ld pushed a commit that referenced this pull request Dec 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[9.21.1](9.21.0...9.21.1)
(2026-11-30)


### Bug Fixes

* Drop track events with a NaN or infinite metric value
([#599](#599))
([6a0e1bf](6a0e1bf))
* Prevent a false synchronizer failure warning when an FDv2 client
closes
([#584](#584))
([5721c67](5721c67))
* Prevent a null prerequisites list from stopping the client from
initializing
([#587](#587))
([298e2a3](298e2a3))
* Prevent an FDv2 initializer result from being applied after close
([#583](#583))
([85e948c](85e948c))
* Report the FDv2 data source status as OFF after close when more
([5721c67](5721c67))
* Restart the stream when a delete event has a version that is not an
integer
([#585](#585))
([cf8b84a](cf8b84a))
* Signal readiness when selectorless initializers are exhausted
([#582](#582))
([fa654b0](fa654b0))


### Documentation

* Explain the cached data warning from the FDv2 file data source
([#591](#591))
([5cc96b0](5cc96b0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> This PR **bumps the LaunchDarkly Python server SDK from 9.21.0 to
9.21.1** via Release Please—updating `pyproject.toml`,
`ldclient/version.py`, `.release-please-manifest.json`, and the
provenance example version.
> 
> The new **CHANGELOG** entry for 9.21.1 documents what ships in this
patch: FDv2 lifecycle and streaming fixes (initializer results after
close, data source status OFF on close, false synchronizer warnings,
non-integer delete versions restarting the stream, selectorless
initializer readiness), client init when prerequisites are null,
dropping track events with NaN/infinite metrics, and docs for the FDv2
file data source cached-data warning.
> 
> No runtime code appears in the diff; this is the release metadata and
changelog for fixes already merged on `main`.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
458695f. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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