{"record":{"id":"22f1f49510b81678","repo":"cocoindex-io/cocoindex","slug":"record-type-must-be-a-record-type-dataclass-name-22f1f4","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/neo4j/_target.py","lineNumber":406,"sourceCode":"        self.row_type = row_type\n\n    @property\n    def value_field_names(self) -> list[str]:\n        \"\"\"Column names other than the primary key, in declared order.\"\"\"\n        return [c for c in self.columns if c != self.primary_key]\n\n    @classmethod\n    async def from_class(\n        cls,\n        record_type: type[RowT],\n        *,\n        primary_key: str = \"id\",\n        column_overrides: dict[str, Neo4jType | res_schema.VectorSchemaProvider]\n        | None = None,\n    ) -> \"TableSchema[RowT]\":\n        \"\"\"Build a TableSchema by introspecting a dataclass / NamedTuple / Pydantic model.\"\"\"\n        if not is_record_type(record_type):\n            raise TypeError(\n                f\"record_type must be a record type (dataclass, NamedTuple, \"\n                f\"Pydantic model), got {type(record_type)}\"\n            )\n        columns = await cls._columns_from_record_type(record_type, column_overrides)\n        return cls(columns, primary_key=primary_key, row_type=record_type)\n\n    @staticmethod\n    async def _columns_from_record_type(\n        record_type: type,\n        column_overrides: dict[str, Neo4jType | res_schema.VectorSchemaProvider] | None,\n    ) -> dict[str, ColumnDef]:\n        record_info = RecordType(record_type)\n        columns: dict[str, ColumnDef] = {}\n\n        for field in record_info.fields:\n            type_info = analyze_type_info(field.type_hint)\n\n            all_annotations: list[Any] = []","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_target.py#L388-L424","documentation":"This TypeError is raised by TableSchema.from_class when the record_type argument is not a supported record type — i.e. not a dataclass, NamedTuple, or Pydantic model, as determined by is_record_type. from_class builds the schema by introspecting the type's fields, which is only possible for those structures. The message includes the actual type received.","triggerScenarios":"Calling TableSchema.from_class with a plain class, a TypedDict, a dict, a NamedTuple-like but unregistered type, or an instance instead of the class — e.g. from_class(dict) or from_class(SomePlainClass).","commonSituations":"Using TypedDict (not supported by is_record_type) instead of dataclass/NamedTuple/Pydantic; forgetting the @dataclass decorator; accidentally passing an instantiated object rather than the type.","solutions":["Annotate the type as a @dataclass, typing.NamedTuple, or Pydantic BaseModel.","Pass the class itself, not an instance: from_class(MyRecord) not from_class(MyRecord()).","Check is_record_type to see exactly which types are accepted."],"exampleFix":"// before\nclass Doc:\n    id: str\n    embedding: list[float]\nTableSchema.from_class(Doc)\n// after\n@dataclass\nclass Doc:\n    id: str\n    embedding: list[float]\nTableSchema.from_class(Doc)","handlingStrategy":"type-guard","validationCode":"import dataclasses, typing\nfrom pydantic import BaseModel\nassert dataclasses.is_dataclass(Record) or issubclass(Record, tuple) or issubclass(Record, BaseModel), \"pass a dataclass/NamedTuple/Pydantic model\"\nTableSchema.from_class(Record)","typeGuard":"from typing import TypeGuard, Any\nimport dataclasses\nfrom pydantic import BaseModel\ndef is_record(t: Any) -> TypeGuard[type]:\n    return dataclasses.is_dataclass(t) or (isinstance(t, type) and issubclass(t, (tuple, BaseModel)))","tryCatchPattern":"try:\n    schema = await TableSchema.from_class(Record)\nexcept TypeError as e:\n    raise TypeError(\"from_class needs a dataclass, NamedTuple, or Pydantic model class\") from e","preventionTips":["Define row records as @dataclass / NamedTuple / BaseModel, never TypedDict or plain classes","Pass the class, not an instance, to from_class","Add a type annotation: def build(rt: type[MyRecord]) so type checkers catch mistakes"],"tags":["neo4j","schema","type-error","dataclass"],"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"}