{"record":{"id":"19ae81725b2fe54d","repo":"cocoindex-io/cocoindex","slug":"record-type-must-be-a-record-type-dataclass-name-19ae81","errorCode":null,"errorMessage":"record_type must be a record type (dataclass, NamedTuple, Pydantic model), got {type(record_type)}","messagePattern":"record_type must be a record type \\(dataclass, NamedTuple, Pydantic model\\), got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/zvec/_target.py","lineNumber":496,"sourceCode":"        record_type: type[RowT],\n        primary_key: list[str],\n        *,\n        column_overrides: dict[\n            str,\n            ZvecType | ZvecVectorDef | ZvecFtsType | res_schema.VectorSchemaProvider,\n        ]\n        | None = None,\n    ) -> \"CollectionSchema[RowT]\":\n        \"\"\"Build a CollectionSchema from a record type.\n\n        Args:\n            record_type: A dataclass, NamedTuple, or Pydantic model.\n            primary_key: Exactly one column name. Its value becomes the document\n                id (converted to ``str``).\n            column_overrides: Optional per-column type/vector overrides.\n        \"\"\"\n        if not is_record_type(record_type):\n            raise TypeError(\n                \"record_type must be a record type (dataclass, NamedTuple, \"\n                f\"Pydantic model), got {type(record_type)}\"\n            )\n        if len(primary_key) != 1:\n            raise ValueError(\n                \"zvec collections require exactly one primary key column \"\n                f\"(mapped to the document id), got {primary_key}.\"\n            )\n\n        record_info = RecordType(record_type)\n        columns: dict[str, _Column] = {}\n        for fld in record_info.fields:\n            override = column_overrides.get(fld.name) if column_overrides else None\n            columns[fld.name] = await _resolve_column(fld.name, fld.type_hint, override)\n        return cls(columns, primary_key[0], row_type=record_type)\n\n\ndef _metric_type(metric: str) -> Any:","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/zvec/_target.py#L478-L514","documentation":"from_class() maps a Python record type (dataclass, NamedTuple, or Pydantic model) to zvec collection columns. If the passed object is not one of these recognized record types (checked via is_record_type), a TypeError is raised because column inference cannot proceed.","triggerScenarios":"Calling RecordTarget.from_class() with a plain dict, TypedDict, plain class, tuple, or an unannotated class instead of a dataclass/NamedTuple/Pydantic model.","commonSituations":"Using a TypedDict (not supported as a record type here); passing a Pydantic v1 model when only v2 is detected; passing the class instance instead of the class; forgetting @dataclass decorator.","solutions":["Decorate the class with @dataclasses.dataclass, or use typing.NamedTuple, or use a Pydantic BaseModel.","Pass the class itself, not an instance.","Check that is_record_type(record_type) returns True before calling from_class."],"exampleFix":"// before\nschema = RecordTarget.from_class({\"id\": str, \"vec\": list[float]}, primary_key=(\"id\",))\n// after\n@dataclass\nclass Doc:\n    id: str\n    vec: list[float]\nschema = RecordTarget.from_class(Doc, primary_key=(\"id\",))","handlingStrategy":"type-guard","validationCode":"import dataclasses\nif not (dataclasses.is_dataclass(record_type) or issubclass(record_type, tuple) or issubclass(record_type, BaseModel)):\n    raise TypeError(\"need dataclass/NamedTuple/Pydantic model\")","typeGuard":"def is_record_type(t: Any) -> bool:\n    import dataclasses\n    return dataclasses.is_dataclass(t) or (isinstance(t, type) and issubclass(t, tuple)) or (isinstance(t, type) and issubclass(t, BaseModel))","tryCatchPattern":"try:\n    target = RecordTarget.from_class(record_type, primary_key=(\"id\",))\nexcept TypeError as e:\n    logging.error(\"unsupported record type: %s\", e)","preventionTips":["Always decorate record classes with @dataclass or subclass NamedTuple/BaseModel.","Pass the class, not an instance, to from_class.","Avoid TypedDict for record schemas."],"tags":["python","type-error","record-type","schema"],"backgroundTag":"invalid-argument-value","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"}