Backend generates invalid JSON with NaN values causing workflow loading failures
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 155
Description
# Backend generates invalid JSON with NaN values causing workflow loading failures
## Problem
When a node's `IS_CHANGED` method throws an exception, ComfyUI sets `node["is_changed"] = float("NaN")`, which produces invalid JSON when serialized. This causes workflows to fail loading when dragged back into the UI.
**Who is affected**: This primarily impacts users who rely on the `prompt` field from PNG metadata - those using ComfyUI via API, headless mode, or alternative frontends. The standard ComfyUI web interface typically uses the `workflow` field (which doesn't contain `is_changed`) and is unaffected unless that field is missing.
## Current Code
In `execution.py` lines 52-60:
```python
try:
is_changed = _map_node_over_list(class_def, input_data_all, "IS_CHANGED")
node["is_changed"] = [None if isinstance(x, ExecutionBlocker) else x for x in is_changed]
except Exception as e:
logging.warning("WARNING: {}".format(e))
node["is_changed"] = float("NaN") # This creates invalid JSON!
finally:
self.is_changed[node_id] = node["is_changed"]
```
When saved to PNG metadata via `json.dumps()`, this produces:
```json
{"is_changed": NaN}
```
This is invalid JSON that cannot be parsed by `JSON.parse()` in browsers.
## Reproduction
1. Create a custom node with an `IS_CHANGED` method that raises an exception
2. Execute a workflow containing this node
3. Save the output image
4. Use a frontend or ComfyUI setup that relies on the `prompt` (API format workflow)
5. Try to load the image with the setup that relies on `prompt`
5. Error: `SyntaxError: JSON.parse: unexpected character`
## Solution
Replace `float("NaN")` with a JSON-serializable value:
```python
except Exception as e:
logging.warning("WARNING: {}".format(e))
# Option 1: Use None (becomes null in JSON)
node["is_changed"] = None
# Option 2: Use a string marker
# node["is_changed"] = "error"
# Option 3: Store error details
# node["is_changed"] = {"error": str(e)}
```
## Impact
This affects users of extensions like:
- was node suite
- dynamicprompts
- Any custom node with buggy `IS_CHANGED` implementations
## Related Issues
- #6915 - Original report of NaN causing workflow loading failures
- Comfy-Org/ComfyUI_frontend#3955 - Frontend PR that exposed this issue more widely
Contributor guide
Assessment
This issue has not been assessed yet.