Repository navigation
fix(workflows): reject non-JSON constants in from_json - #5250
Merged
Merged
Conversation
Assisted-by: Codex (model: GPT-6, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change rejecting non-JSON numeric constants in from_json.
No open issues 🎉
What changed in this PR
This PR tightens the workflow expression filter from_json to reject Python-only numeric constants while preserving valid JSON values and existing numeric range behavior.
Changes:
- Reject bare
NaN,Infinity, and-Infinity, including inside arrays and objects. - Add regression coverage for rejected constants, workflow conditions, and accepted JSON values.
- Document the distinction between bare constants and valid quoted strings.
The PR reports before-and-after regression evidence and a passing full test suite; these results were not independently rerun.
| File | Description |
|---|---|
tests/test_workflows.py |
Adds rejection and valid-input regression tests. |
src/specify_cli/workflows/expressions/filters.py |
Adds a rejecting parse_constant callback to JSON decoding. |
docs/workflows/expressions.md |
Documents non-JSON constant rejection and quoted-string acceptance. |
Review effort: Balanced (auto)
Collaborator
|
Thank you! |
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.
Description
from_jsonpromises an error for invalid JSON, but Python's default decoder accepts the bare tokensNaN,Infinity, and-Infinity. These are not JSON numbers (RFC 8259, section 6). They can reach workflow conditions or downstream shell-step environment values instead of failing conversion.In a local workflow run with
VALUE: "value={{ inputs.payload | from_json }}", each of the three tokens currently produces exit code 0 and runs the consumer withnan,inf, or-inf. With this change, the run exits 1 withfrom_json: invalid JSON constant: ...and the consumer is not executed.Pass a rejecting
parse_constantcallback tojson.loads. This covers constants at the root and inside arrays/objects while preserving quoted text such as"NaN", ordinary numbers, booleans and null. Document the boundary explicitly. Previously accepted Python-only numeric constants now raise; numeric range/precision behavior is unchanged.Testing
Tested locally with
uv run specify --helpRan existing tests using this checkout's
.venv/bin/pythonafteruv sync --extra testTested with a sample project (local workflow CLI, no model or remote service)
New regression cases on unmodified
mainatec9a6f3b94c0aa856f77e550785a1ddde1993de1: 12 failed, 9 passed, with no collection errors..venv/bin/python -m pytest tests/test_workflows.py -q: 882 passed after the fix..venv/bin/python -m pytest tests -n 4 -q: 13,936 passed, 440 skipped (0 failures; 63 warnings).Five CLI cases: all three invalid constants stop before the consumer runs; quoted
"NaN"andtruestill complete successfully.CI-pinned
uvx ruff@0.15.0 check src tests, Markdownlint on the changed documentation, the configured pre-commit hooks for the changed files, andgit diff --check: passed.An earlier
--maxfail=1full run stopped after 13,758 passes and 440 skips on the unchangedTestInitStep::test_failed_init_surfaces_inits_own_message, whose captured output contained catalog-fetch HTTP 403 warnings. That test passed when run alone on this branch, and all 16TestInitSteptests passed on the unmodified base through an isolated import path. Without further code changes, the complete full-suite rerun passed with the result reported above; it included the previously failing test.No slash-command templates or scaffolding behavior changed; the affected manual path is the workflow CLI.
Validation environment: Linux, Python 3.12.14. Other OS/Python matrix combinations were not run locally.
Test selection reasoning
src/specify_cli/workflows/expressions/filters.pyspecify workflow runexpression conversiontests/test_workflows.pydocs/workflows/expressions.mdRequired tests
specify workflow run <file> --input payload=<value> --json; check the exit code and whether the consumer created its marker.@mschoi0411 requested this bug-fix contribution and reviewed the explanation before approving submission; Codex (GPT-6, autonomous mode; reasoning-effort setting unavailable) selected and diagnosed the bug, wrote the fix, tests, documentation and this PR description, and ran the automated validation.