{"record":{"id":"ca63ba25e497c9c1","repo":"cocoindex-io/cocoindex","slug":"record-type-must-be-a-record-type-dataclass-name-ca63ba","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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/falkordb/_target.py","lineNumber":366,"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, FalkorType | 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, FalkorType | res_schema.VectorSchemaProvider]\n        | 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","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/falkordb/_target.py#L348-L384","documentation":"`TableSchema.from_class` introspects the given type to derive columns; it only supports record types (dataclass, NamedTuple, Pydantic model) via `is_record_type`. Passing any other type (plain class, dict, typing construct) raises TypeError because there is no field metadata to introspect.","triggerScenarios":"Calling `await TableSchema.from_class(dict)` or `from_class(SomePlainClass)` or passing an instance instead of the class; also passing generic aliases like `list[Row]`.","commonSituations":"Passing an instantiated dataclass object rather than the class; using a TypedDict or plain dict as the row type; refactoring away from dataclass without updating from_class calls.","solutions":["Pass the class itself, not an instance: `from_class(Row, ...)` not `from_class(row, ...)`.","Convert the row type to a `@dataclass`, `NamedTuple`, or Pydantic `BaseModel`.","If the type is a TypedDict, migrate it to a dataclass since TypedDict is not supported here."],"exampleFix":"// before\nschema = await falkordb.TableSchema.from_class(row_instance)\n// after\n@dataclasses.dataclass\nclass Row: id: str; text: str\nschema = await falkordb.TableSchema.from_class(Row, primary_key=\"id\")","handlingStrategy":"type-guard","validationCode":"import dataclasses, typing\nif not (dataclasses.is_dataclass(Row) or issubclass(Row, tuple) or issubclass(Row, BaseModel)):\n    raise TypeError(\"from_class needs a dataclass / NamedTuple / Pydantic model class\")","typeGuard":"def is_record_type(t: object) -> 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    schema = await falkordb.TableSchema.from_class(Row)\nexcept TypeError as e:\n    if \"must be a record type\" in str(e):\n        logging.error(\"Pass the class, not an instance; use @dataclass/NamedTuple/Pydantic: %s\", e)\n    raise","preventionTips":["Pass the class object, never an instance.","Use @dataclass for all row types passed to from_class.","Enable mypy so non-class arguments are caught statically."],"tags":["python","falkordb","type-error","record-type"],"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"}