mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-23 03:26:53 +08:00
## Summary Fixes #12631 When SQL query results contain NaN (Not a Number) or Infinity values (e.g., from division by zero or other calculations), the JSON serialization would fail because **NaN and Infinity are not valid JSON values**. This caused the agent interface to show 'undefined' error, as described in the issue where `EXAMINE_TIMES` became `NaN` and broke the JSON parsing. ## Root Cause The `convert_decimals` function in `exesql.py` was only handling `Decimal` types, but not `float` values that could be `NaN` or `Infinity`. When these invalid JSON values were serialized: ```json {"EXAMINE_TIMES": NaN} // Invalid JSON! ``` The frontend JSON parser would fail, causing the 'undefined' error. ## Solution Extended `convert_decimals` to detect `float` values and convert `NaN`/`Infinity` to `null` before JSON serialization: ```python if isinstance(obj, float): if math.isnan(obj) or math.isinf(obj): return None return obj ``` This ensures all SQL results can be properly serialized to valid JSON. --- This is a Gittensor contribution. gittensor:user:GlobalStar117 Co-authored-by: GlobalStar117 <GlobalStar117@users.noreply.github.com> Co-authored-by: Jin Hai <haijin.chn@gmail.com> Co-authored-by: Zhichang Yu <yuzhichang@gmail.com>