fix(dupont): resolve YYYY-Qn / YYYY-Hn period windows (500 on quarter/half)
ci/woodpecker/push/main Pipeline failed
ci/woodpecker/push/main Pipeline failed
Root cause: resolve_window() matched quarter/half with p[4] == "q" / "h"
(always '-' for "2026-q2"/"2026-h1"), and the branches sat after the
single-month branch -> dead code. Real input fell into the month branch,
so months_between() raised ValueError on int('q2') -> HTTP 500 for all
18 quarter/half options in the period selector.
Fix: judge on p[5] in ("q","h") with a digit guard on p[6], evaluated
before the single-month branch; month branch tightened to p[5:].isdigit().
Existing error-branch wording unchanged.
Tests: backend/tests/test_dupont_period_options.py (18 defect options,
case equivalence, month/year/ytd/ttm/custom non-regression, malformed
input returns error dict instead of raising).
This commit is contained in:
@@ -197,17 +197,17 @@ def resolve_window(period: Optional[str], start: Optional[str], end: Optional[st
|
||||
return {"error": "自定义区间须同时给出 start 与 end(YYYY-MM)"}
|
||||
s, e = start, end
|
||||
key = "custom"
|
||||
elif len(p) == 7 and p[4] == "-": # 2026-08 → 单月
|
||||
s = e = p
|
||||
key = "month"
|
||||
elif len(p) == 7 and p[4] == "q": # 2026-q3
|
||||
elif len(p) == 7 and p[5] == "q" and p[6].isdigit(): # 2026-q3
|
||||
y, q = int(p[:4]), int(p[6])
|
||||
s, e = f"{y}-{(q - 1) * 3 + 1:02d}", f"{y}-{q * 3:02d}"
|
||||
key = "quarter"
|
||||
elif len(p) == 7 and p[4] == "h": # 2026-h1
|
||||
elif len(p) == 7 and p[5] == "h" and p[6].isdigit(): # 2026-h1
|
||||
y, h = int(p[:4]), int(p[6])
|
||||
s, e = f"{y}-{(h - 1) * 6 + 1:02d}", f"{y}-{h * 6:02d}"
|
||||
key = "half"
|
||||
elif len(p) == 7 and p[5:].isdigit(): # 2026-08 → 单月
|
||||
s = e = p
|
||||
key = "month"
|
||||
elif len(p) == 4 and p.isdigit(): # 2026 → 全年
|
||||
s, e = f"{p}-01", f"{p}-12"
|
||||
key = "year"
|
||||
|
||||
Reference in New Issue
Block a user