Repository navigation
fix(attributes): Handle special float values correctly - #8067
Conversation
| if isinstance(val, float) and (math.isinf(val) or math.isnan(val)): | ||
| return str(val) | ||
|
|
There was a problem hiding this comment.
Non-finite float-array attributes still break envelope JSON serialization
Homogeneous float lists and tuples containing NaN or infinity pass through format_attribute unchanged. serialize_attribute then emits them as array values, but envelope payloads are encoded with json_dumps(allow_nan=False), which raises ValueError. Normalize non-finite elements in float arrays before serialization, or otherwise ensure the resulting payload is valid JSON.
Evidence
format_attributehandles non-finite values only in its scalar-float branch; its homogeneous list and tuple branches return float elements unchanged.serialize_attributeemits homogeneous lists as array values, so a value such as[float("nan")]remains in the payload.- Batchers place these serialized attributes in JSON payloads;
PayloadRef.get_bytes()encodes them withjson_dumps, which setsallow_nan=Falseand raisesValueErrorfor NaN or infinity.
Also found at 1 additional location
tests/test_attributes.py:228-234
Identified by Warden · code-review · D6L-C4X
Coverage Results 📊✅ 133717 passed | ⏭️ 7276 skipped | Total: 140993 | Pass Rate: 94.84% | Execution Time: 466m 14s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 100.00% (2 of 2 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8067 +/-##
==========================================
Coverage 90.26% 90.26% —%
==========================================
Files 202 202 —
Tracked lines 26660 26662 +2
Branches 9926 9928 +2
==========================================
+ Hits 24062 24065 +3
+ Misses 2598 2597 -1
+ Partials 1510 1509 -1Generated by Coverage Action |
Fixes #8066