{"record":{"id":"792577a2f49fac45","repo":"calesthio/OpenMontage","slug":"element-id-must-be-an-integer-compatible-value-r","errorCode":null,"errorMessage":"element_id must be an integer-compatible value: {raw_id!r}","messagePattern":"element_id must be an integer-compatible value: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/_kling/elements.py","lineNumber":36,"sourceCode":"\n    if not element_list:\n        return []\n    if not isinstance(element_list, list):\n        raise ValueError(\"element_list must be a list of element ids or objects\")\n\n    normalized: list[dict[str, int]] = []\n    for item in element_list:\n        raw_id: Any\n        if isinstance(item, dict):\n            raw_id = item.get(\"element_id\", item.get(\"id\"))\n        else:\n            raw_id = item\n        if raw_id is None:\n            raise ValueError(\"each element_list item must include element_id\")\n        try:\n            element_id = int(raw_id)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"element_id must be an integer-compatible value: {raw_id!r}\") from exc\n        if element_id <= 0:\n            raise ValueError(\"element_id must be positive\")\n        normalized.append({\"element_id\": element_id})\n    return normalized\n\n\ndef element_ids(element_list: Any | None) -> list[int]:\n    \"\"\"Return normalized element ids from an element reference list.\"\"\"\n\n    return [item[\"element_id\"] for item in normalize_element_list(element_list)]\n\n\ndef get_custom_element(element_id: int, client: KlingClient | None = None) -> dict[str, Any]:\n    \"\"\"Fetch one custom element for validation or diagnostics.\"\"\"\n\n    api = client or KlingClient()\n    return api.get(f\"/v1/general/advanced-custom-elements/{int(element_id)}\")\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/elements.py#L18-L54","documentation":"Raised when the extracted element id cannot be converted with int(raw_id). int() accepts ints, floats, and numeric strings, but fails on non-numeric strings ('abc'), None is caught earlier, and values like '12.5' or '1_2' also raise. The original value is included in the message via repr.","triggerScenarios":"Passing a UUID or slug string as an element id ('elm_abc123'); a float string like '12.5'; a dict whose element_id value is itself a dict/list; ids from a different API that are alphanumeric rather than integer.","commonSituations":"Confusing custom-element ids (integers) with other Kling resource ids (task ids, which are strings); pasting ids from a UI that appends formatting; LLM hallucinating id formats.","solutions":["Use the integer id returned by the custom-element creation endpoint (get_custom_element shows the expected shape)","Strip non-numeric prefixes/suffixes before passing if your source adds them","If ids can genuinely be non-integer in your flow, stop using normalize_element_list and pass the official element_list format directly to the API"],"exampleFix":"// before\nrefs = normalize_element_list(['elm_0000123'])\n\n// after\nrefs = normalize_element_list([123])  # integer id from the element creation response","handlingStrategy":"validation","validationCode":"def is_int_like_id(value) -> bool:\n    if isinstance(value, bool):\n        return False\n    if isinstance(value, int):\n        return True\n    if isinstance(value, str):\n        return value.strip().lstrip('+-').isdigit()\n    return False","typeGuard":"def to_element_id(value):\n    try:\n        return int(value)\n    except (TypeError, ValueError):\n        return None  # explicit None => caller rejects instead of crashing","tryCatchPattern":"try:\n    refs = normalize_element_list(items)\nexcept ValueError as e:\n    if 'integer-compatible' in str(e):\n        raise ValueError('element ids must be integers from the element-creation API, not slugs/uuids') from e\n    raise","preventionTips":["Take element ids only from the custom-element create/list API responses (they are integers)","Never substitute task ids or other string identifiers as element ids","Validate ids are int-like before building the payload"],"tags":["kling","elements","validation","type-coercion"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}