fix(query): normalize NaN cells to None in query_files_by_selector - #21
Merged
Conversation
df.to_dict(orient="records") preserves pandas NaN as float("nan"), which
Python's default json.dumps(allow_nan=True) emits as the literal token
"NaN" — not valid JSON. JS clients that JSON.parse the result silently
fall through to a raw-string path. In chatbox-core that bypasses both
_engine_dispatched and _cache_uri injection (engine/index.js:1060
gates on isObjResult, which is false for strings). Affected every
hydrology query result that touched the troute "nudge" column on a
non-assimilated reach.
The sibling code path at logic.py:754 already applied _normalize_record
for the same reason. This brings line 649 in line with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
logic.py:649: wrapdf.to_dict(orient="records")in[_normalize_record(r) for r in ...]so NaN cells becomeNonebefore envelope serializationjson.dumps(allow_nan=False)Why
df.to_dict(orient="records")preserves pandas NaN asfloat("nan"), which Python's defaultjson.dumps(allow_nan=True)emits as the literal tokenNaN— not valid JSON. JS clients thatJSON.parsethe result silently fall through to a raw-string path.In chatbox-core that bypasses both
_engine_dispatchedand_cache_uriinjection:engine/index.js:1060gates the injection block ontypeof toolResult === "object", which is false for strings. Affected every hydrology query result that touched the troutenudgecolumn on a non-assimilated reach.The sibling code path at
logic.py:754already applied_normalize_recordfor the same reason. This brings line 649 in line.Test plan
test_nan_cells_serialize_to_valid_jsonround-trips the envelope throughjson.loads(json.dumps(..., allow_nan=False))