{"record":{"id":"996d06950d954e8a","repo":"Comfy-Org/ComfyUI","slug":"aspect-ratio-parts-must-be-positive-integers-got","errorCode":null,"errorMessage":"Aspect ratio parts must be positive integers, got {a}:{b}.","messagePattern":"Aspect ratio parts must be positive integers, got (.+?):(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/util/validation_utils.py","lineNumber":244,"sourceCode":"            raise ValueError(f\"Aspect ratio `{ar:.2g}` must be {op} {lo:.2g}.\")\n    if hi is not None:\n        if (ar >= hi) if strict else (ar > hi):\n            op = \"<\" if strict else \"≤\"\n            raise ValueError(f\"Aspect ratio `{ar:.2g}` must be {op} {hi:.2g}.\")\n\n\ndef _parse_aspect_ratio_string(ar_str: str) -> float:\n    \"\"\"Parse 'X:Y' with integer parts into a positive float ratio X/Y.\"\"\"\n    parts = ar_str.split(\":\")\n    if len(parts) != 2:\n        raise ValueError(f\"Aspect ratio must be 'X:Y' (e.g., 16:9), got '{ar_str}'.\")\n    try:\n        a = int(parts[0].strip())\n        b = int(parts[1].strip())\n    except ValueError as exc:\n        raise ValueError(f\"Aspect ratio must contain integers separated by ':', got '{ar_str}'.\") from exc\n    if a <= 0 or b <= 0:\n        raise ValueError(f\"Aspect ratio parts must be positive integers, got {a}:{b}.\")\n    return a / b\n","sourceCodeStart":226,"sourceCodeEnd":246,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/util/validation_utils.py#L226-L246","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\nw, h = 0, 9\n_parse_aspect_ratio_string(f'{w}:{h}')  # ValueError: parts must be positive integers, got 0:9.\n\n# after\nassert w > 0 and h > 0, 'dimensions must be positive'\n_parse_aspect_ratio_string(f'{w}:{h}')","handlingStrategy":"type-guard","validationCode":"a, b = (int(p.strip()) for p in ratio_str.split(':'))\nif a <= 0 or b <= 0:\n    raise ValueError(f'degenerate ratio {ratio_str!r}; both parts must be > 0')","typeGuard":"def is_positive_int_ratio(s: str) -> bool:\n    parts = s.split(':')\n    if len(parts) != 2: return False\n    try:\n        a, b = int(parts[0].strip()), int(parts[1].strip())\n        return a > 0 and b > 0\n    except ValueError:\n        return False","tryCatchPattern":null,"preventionTips":["Never build ratio strings from possibly-zero dimensions.","Assert both dimensions positive after loads/crops.","Default to '16:9' when dimensions are unknown."],"tags":["api-nodes","validation","aspect-ratio","parsing"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}