Comfy-Org/ComfyUI · error · ValueError
Aspect ratio parts must be positive integers, got {a}:{b}.
Error message
Aspect ratio parts must be positive integers, got {a}:{b}. What it means
Raised by _parse_aspect_ratio_string() in comfy_api_nodes/util/validation_utils.py when both parts parse as integers but one is zero or negative. The helper must return a positive float ratio, so '0:9', '-16:9', or '16:0' are rejected after successful int parsing.
Source
Thrown at comfy_api_nodes/util/validation_utils.py:244
raise ValueError(f"Aspect ratio `{ar:.2g}` must be {op} {lo:.2g}.")
if hi is not None:
if (ar >= hi) if strict else (ar > hi):
op = "<" if strict else "≤"
raise ValueError(f"Aspect ratio `{ar:.2g}` must be {op} {hi:.2g}.")
def _parse_aspect_ratio_string(ar_str: str) -> float:
"""Parse 'X:Y' with integer parts into a positive float ratio X/Y."""
parts = ar_str.split(":")
if len(parts) != 2:
raise ValueError(f"Aspect ratio must be 'X:Y' (e.g., 16:9), got '{ar_str}'.")
try:
a = int(parts[0].strip())
b = int(parts[1].strip())
except ValueError as exc:
raise ValueError(f"Aspect ratio must contain integers separated by ':', got '{ar_str}'.") from exc
if a <= 0 or b <= 0:
raise ValueError(f"Aspect ratio parts must be positive integers, got {a}:{b}.")
return a / b
View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Use positive integers on both sides, e.g. '16:9'.
- If constructing from dimensions, validate both are > 0 before formatting the string.
- Fix the upstream computation that produced a zero dimension (bad load, empty tensor shape).
- Guard with a default ratio when dimensions are unknown.
Example fix
# before
w, h = 0, 9
_parse_aspect_ratio_string(f'{w}:{h}') # ValueError: parts must be positive integers, got 0:9.
# after
assert w > 0 and h > 0, 'dimensions must be positive'
_parse_aspect_ratio_string(f'{w}:{h}') Defensive patterns
Strategy: type-guard
Validate before calling
a, b = (int(p.strip()) for p in ratio_str.split(':'))
if a <= 0 or b <= 0:
raise ValueError(f'degenerate ratio {ratio_str!r}; both parts must be > 0') Type guard
def is_positive_int_ratio(s: str) -> bool:
parts = s.split(':')
if len(parts) != 2: return False
try:
a, b = int(parts[0].strip()), int(parts[1].strip())
return a > 0 and b > 0
except ValueError:
return False Prevention
- Never build ratio strings from possibly-zero dimensions.
- Assert both dimensions positive after loads/crops.
- Default to '16:9' when dimensions are unknown.
When it happens
Trigger: Passing '0:0', '16:0', '0:9', or negative components like '-1:1' through validate_aspect_ratio — usually from programmatic construction where a width or height was 0 (e.g. 'derive height from aspect' computed 0).
Common situations: Scripts building the ratio string from image dimensions where one dimension is 0 due to a failed load or a division that collapsed to zero; users experimenting with degenerate values; template substitution inserting an unset variable as 0.
Related errors
- Aspect ratio must be 'X:Y' (e.g., 16:9), got '{ar_str}'.
- Aspect ratio must contain integers separated by ':', got '{a
- Ratios must be positive, got {a}:{b}.
- Aspect ratio `{ar:.2g}` must be {op} {lo:.2g}.
- Aspect ratio `{ar:.2g}` must be {op} {hi:.2g}.
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/996d06950d954e8a.
Report an issue: GitHub.