[Bug]: Unsupported expression syntax evaluates to None silently instead of raising
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #5206 của @aarjang — đã đóng, không merge
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start in src/specify_cli/workflows/expressions.py, especially the parser and evaluation points cited in the report: lines 304, 331, 715, 800, 884, 893, 930-976, and _safe_compare. Read the evaluator tests in tests/test_workflows.py and run the reproductions from the issue for exponent numbers, escaped quotes, chained indexing, and adjacent word operators. Done means each documented case evaluates as expected or raises a clear ValueError for unsupported syntax.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Description
When the workflow expression evaluator meets syntax it does not parse, it does not raise. It treats the text as a variable path, which resolves to None (_resolve_dot_path, reached from src/specify_cli/workflows/expressions.py:969). A condition that uses such syntax then quietly gives the wrong result. The following cases were confirmed:
- Exponent-form numbers. Numeric literals and numeric strings are parsed with
float()only when they contain a., and otherwise withint()(expressions.py:930-935for literals,expressions.py:972-976for_coerce_number). So1e3is not read as a number: as a literal it is looked up as a variable and becomesNone, and the string"1e3"stays a string in comparisons. Workflow input coercion does accept"1e3"as the number1000(src/specify_cli/workflows/engine.py:1449-1456), so the same text means different things in different places. - Escaped quotes in string literals. A string literal is recognised only if its first matching quote is its last character (
expressions.py:800), so'it\'s'is looked up as a variable and becomesNone. As a result,inputs.name == 'it\'s'is false forname = "it's". - Chained indexing. The indexed-segment pattern accepts one index only (
expressions.py:304), somatrix[0][1]is looked up as the literal key"matrix[0][1]"(expressions.py:331) and returnsNone. - Word operators next to a quote.
and,orandinare only found with a space on both sides (expressions.py:884,expressions.py:893,expressions.py:715).inputs.a=='x'and inputs.bis therefore split only at==, its right side'x'and inputs.bis looked up as a variable and becomesNone, and the result is false.
Steps to Reproduce
- From a fresh clone of spec-kit, run
uv sync. - Save the script below as
repro.pyin the repository root. - Run
uv run python -I repro.py.
from specify_cli.workflows.base import StepContext
from specify_cli.workflows.engine import WorkflowEngine
from specify_cli.workflows.expressions import evaluate_condition, evaluate_expression
ctx = StepContext(
inputs={"n": 5, "s": "1e3", "name": "it's", "a": "x", "b": True},
steps={"plan": {"output": {"matrix": [["a", "b"], ["c", "d"]]}}},
)
cases = [
("1", "{{ 1e3 }}", "value"),
("1", "{{ inputs.n < 1e3 }}", "cond"),
("1", "{{ inputs.s > 100 }}", "cond"),
("2", r"{{ 'it\'s' }}", "value"),
("2", r"{{ inputs.name == 'it\'s' }}", "cond"),
("3", "{{ steps.plan.output.matrix[0] }}", "value"),
("3", "{{ steps.plan.output.matrix[0][1] }}", "value"),
("4", "{{ inputs.a == 'x' and inputs.b }}", "cond"),
("4", "{{ inputs.a=='x'and inputs.b }}", "cond"),
("4", "{{ 'x'in inputs.a }}", "cond"),
]
for num, expr, kind in cases:
fn = evaluate_expression if kind == "value" else evaluate_condition
print(f"[{num}] {expr} -> {fn(expr, ctx)!r}")
print("input coercion of '1e3' (type: number):",
WorkflowEngine._coerce_input("x", "1e3", {"type": "number"}))
Expected Behavior
The module docstring describes the evaluator as "a safe Jinja2 subset" (src/specify_cli/workflows/expressions.py:3), and _evaluate_simple_expression lists "String and numeric literals" as supported (expressions.py:791). For each case, the expression should either evaluate as it would in Jinja2 or raise a ValueError naming the unsupported syntax. Malformed filters already get such a ValueError (docs/reference/workflows.md, "Types are validated, not coerced"). Specifically:
{{ 1e3 }}should be1000.0, and{{ inputs.n < 1e3 }}should be true forn = 5.{{ inputs.s > 100 }}withs = "1e3"should be true, in line with the_safe_comparedocstring (expressions.py:1003-1012) and the input-coercion testtests/test_workflows.py:7092(("1e3", 1000)).{{ 'it\'s' }}should be"it's", and the comparison should be true.{{ steps.plan.output.matrix[0][1] }}should be'b'. The_resolve_dot_pathdocstring promises list indexing (expressions.py:312).{{ inputs.a=='x'and inputs.b }}should be true, like the spaced form.{{ 'x'in inputs.a }}should be true.
Actual Behavior
[1] {{ 1e3 }} -> None
[1] {{ inputs.n < 1e3 }} -> False
[1] {{ inputs.s > 100 }} -> False
[2] {{ 'it\'s' }} -> None
[2] {{ inputs.name == 'it\'s' }} -> False
[3] {{ steps.plan.output.matrix[0] }} -> ['a', 'b']
[3] {{ steps.plan.output.matrix[0][1] }} -> None
[4] {{ inputs.a == 'x' and inputs.b }} -> True
[4] {{ inputs.a=='x'and inputs.b }} -> False
[4] {{ 'x'in inputs.a }} -> False
input coercion of '1e3' (type: number): 1000
Specify CLI Version
1.2.4.dev0 (main at 27d14e2)
AI Agent
Not applicable
Operating System
Linux 6.18 (Ubuntu container)
Python Version
Python 3.12.3
Additional Context
When cases 1, 3 and 4 are used as an if condition, validate_workflow returns no errors. Case 2 is flagged in a condition, but as unbalanced delimiters and quotes rather than as an escaped quote.
Related: #5060 proposes replacing the hand-written expression parser with a grammar so that invalid input raises. It does not mention this case.
Also reproduced on macOS (Darwin 25.6, arm64) with Python 3.14.4 and uv run python -I repro.py against 27d14e2; the output matches the above.
AI Disclosure
Found and reproduced with Claude Code (model: Claude Opus 4.8), run autonomously under human supervision. The human reporter re-ran every reproduction above before filing.
- Ngôn ngữ chính
- Python
- Star
- 149k
- Fork
- 13.4k
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 223
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/spec-kit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
triage-must-have
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Workflow-step verifier test fixture breaks when the checkout path contains whitespace (4 failures on macOS)Có thể đã có người làm @mehdikarimi55 đã nhận 3 ngày trước. Đang mởtriage-can-wait
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Parity tests fail under the documented direct pytest invocation when the ambient python3 lacks PyYAML (11 failures)Có thể đã có người làm @mehdikarimi55 đã nhận 3 ngày trước. Đang mởtriage-must-have
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug triage-out-of-scope
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của github/spec-kit
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
glossyio/traffic-monitor#312 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
local devenv exampleĐang mởdocumentation enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
es-ude/elastic-ai.creator#1046 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
ENH: permit cachetools >= 7Đang mởfeature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
confident-ai/deepteam#306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SslLibrary crashes with unhandled OSError: port/proto not found on non-standard SSL portsCó thể đã có người làm @himanchalkaushale đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OWASP/Nettacker#1884 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày