{"record":{"id":"1d01f88267e3eaeb","repo":"cocoindex-io/cocoindex","slug":"unsupported-record-type-self-record-type","errorCode":null,"errorMessage":"Unsupported record type: {self.record_type}","messagePattern":"Unsupported record type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/_internal/datatype.py","lineNumber":162,"sourceCode":"                yield RecordFieldInfo(\n                    name=name,\n                    type_hint=type_hints.get(name, Any),\n                    default_value=defaults.get(name, inspect.Parameter.empty),\n                    description=None,\n                )\n        elif is_pydantic_model(self.record_type):\n            model_fields = getattr(self.record_type, \"model_fields\", {})\n            for name, field_info in model_fields.items():\n                yield RecordFieldInfo(\n                    name=name,\n                    type_hint=type_hints.get(name, Any),\n                    default_value=field_info.default\n                    if field_info.default is not ...\n                    else inspect.Parameter.empty,\n                    description=field_info.description,\n                )\n        else:\n            raise ValueError(f\"Unsupported record type: {self.record_type}\")\n\n\nclass UnionType(NamedTuple):\n    \"\"\"\n    Any union type, e.g. T1 | T2 | ..., etc.\n    \"\"\"\n\n    variant_types: list[Any]\n\n\nclass MappingType(NamedTuple):\n    \"\"\"\n    Any dict type, e.g. dict[T1, T2], Mapping[T1, T2], etc.\n    \"\"\"\n\n    key_type: Any\n    value_type: Any\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/datatype.py#L144-L180","documentation":"RecordType.fields can extract field metadata only from dataclasses, NamedTuples, and Pydantic models — the types is_record_type recognizes. If a RecordType was constructed for some other type, iterating .fields falls through all branches and raises ValueError.","triggerScenarios":"Passing a plain class, TypedDict, attrs class (without recognition), or a NamedTuple-like object lacking _fields into a code path that wraps it in RecordType and iterates fields; or is_record_type and fields going out of sync (e.g. a type that passed the record check but whose specific kind isn't handled).","commonSituations":"Using TypedDict for schema rows (not supported); defining a custom struct class and expecting it to be treated as a record; a library upgrade changing the recognized record kinds.","solutions":["Convert the type to a @dataclass, typing.NamedTuple, or pydantic.BaseModel","Check is_record_type(t) before constructing RecordType in custom analysis code","If using TypedDict, switch to a dataclass with equivalent fields"],"exampleFix":"// before\nclass Row(TypedDict):\n    id: int\n\n// after\n@dataclasses.dataclass\nclass Row:\n    id: int","handlingStrategy":"type-guard","validationCode":"from cocoindex._internal.datatype import is_record_type\nif not is_record_type(Row):\n    raise TypeError(f\"{Row} must be dataclass/NamedTuple/pydantic model\")","typeGuard":"def is_valid_record(t: type) -> bool:\n    return dataclasses.is_dataclass(t) or hasattr(t, \"_fields\") or (\n        PYDANTIC_AVAILABLE and issubclass(t, pydantic.BaseModel))","tryCatchPattern":"try:\n    fields = list(RecordType(record_type=Row).fields)\nexcept ValueError as e:\n    logging.error(\"record type unsupported: %s\", e)\n    Row = dataclasses.dataclass(Row)  # or switch to a supported class","preventionTips":["Use @dataclass, typing.NamedTuple, or pydantic.BaseModel for all record schemas","Avoid TypedDict and plain classes for indexed records","Run schema analysis in unit tests so unsupported types surface early"],"tags":["python","schema","record-type"],"backgroundTag":"incompatible-source-type","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}