{"record":{"id":"6d014d2587cf6fb6","repo":"calesthio/OpenMontage","slug":"element-list-must-be-a-list-of-element-ids-or-obje","errorCode":null,"errorMessage":"element_list must be a list of element ids or objects","messagePattern":"element_list must be a list of element ids or objects","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/_kling/elements.py","lineNumber":22,"sourceCode":"internal provider reference mechanism in Phase 2, not a registry capability.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport json\nfrom pathlib import Path\nfrom typing import Any\n\nfrom .client import KlingClient\n\n\ndef normalize_element_list(element_list: Any | None) -> list[dict[str, int]]:\n    \"\"\"Normalize official Kling element references to element_list objects.\"\"\"\n\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","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/elements.py#L4-L40","documentation":"Raised by normalize_element_list() in tools/_kling/elements.py when element_list is truthy but not a Python list. The function accepts a list of element ids (ints/strings) or objects ({element_id} / {id}), but rejects any other type before iterating.","triggerScenarios":"Passing a bare int or string id ('12345'), a single dict instead of a list of dicts, a comma-separated string ('1,2,3'), or a tuple/JSON string that was never parsed — any of these is truthy but fails isinstance(element_list, list).","commonSituations":"Caller forwards an LLM/tool-produced JSON string without json.loads; caller grabs one element id from a previous response and passes it directly; YAML/JSON config where a single item is written as a scalar instead of a one-element list.","solutions":["Wrap the value in a list: pass [element_id] instead of element_id","If the value arrives as a JSON string, json.loads() it before calling","Coerce tuples/sets to list before passing"],"exampleFix":"// before\nrefs = normalize_element_list(element_id)          # bare int\nrefs = normalize_element_list('{\"element_id\": 1}')  # JSON string\n\n// after\nrefs = normalize_element_list([element_id])\nrefs = normalize_element_list(json.loads('[{\"element_id\": 1}]'))","handlingStrategy":"type-guard","validationCode":"import json\n\ndef coerce_element_list(value):\n    if isinstance(value, str):\n        value = json.loads(value)          # accept JSON strings\n    if isinstance(value, (int, str)) or (isinstance(value, dict) and value):\n        value = [value]                    # accept a single item\n    return value if isinstance(value, list) else None  # None => caller should reject","typeGuard":"def is_valid_element_list(value) -> bool:\n    return value is None or (isinstance(value, list) and len(value) > 0)","tryCatchPattern":"from tools._kling.elements import normalize_element_list\n\ntry:\n    refs = normalize_element_list(raw_value)\nexcept ValueError as e:\n    raise ValueError(f'bad element_list {raw_value!r}: {e}') from e","preventionTips":["Always pass a list, even for one element: [element_id]","json.loads() strings from LLM/tool output before use","Document the accepted shapes (list of ints, numeric strings, {element_id}/{id} dicts) at call sites"],"tags":["kling","elements","validation","input-shape"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}