cocoindex-io/cocoindex · error · TypeError

record_type must be a record type, got {type(record_type)}

Error message

record_type must be a record type, got {type(record_type)}

What it means

DorisTableSchema.from_class requires the record_type argument to be a cocoindex record type (verified by is_record_type). Any other object (plain dict, dataclass not registered, None) cannot be introspected into columns, so a TypeError is raised.

Source

Thrown at python/cocoindex/connectors/doris/_target.py:370

        self.primary_key = primary_key
        self.row_type = row_type
        for pk in self.primary_key:
            if pk not in self.columns:
                raise ValueError(
                    f"PK column '{pk}' not in columns: {list(self.columns.keys())}"
                )

    @classmethod
    async def from_class(
        cls,
        record_type: type[RowT],
        primary_key: list[str],
        *,
        column_overrides: dict[str, DorisType | res_schema.VectorSchemaProvider]
        | None = None,
    ) -> "TableSchema[RowT]":
        if not is_record_type(record_type):
            raise TypeError(
                f"record_type must be a record type, got {type(record_type)}"
            )
        columns = await cls._columns_from_record_type(record_type, column_overrides)
        return cls(columns, primary_key, row_type=record_type)

    @staticmethod
    async def _columns_from_record_type(
        record_type: type,
        column_overrides: dict[str, DorisType | res_schema.VectorSchemaProvider] | None,
    ) -> dict[str, ColumnDef]:
        record_info = RecordType(record_type)
        columns: dict[str, ColumnDef] = {}

        for f in record_info.fields:
            override = column_overrides.get(f.name) if column_overrides else None
            type_info = analyze_type_info(f.type_hint)

            all_annotations = []

View on GitHub (pinned to e84aa99b32)

Solutions

  1. Pass a cocoindex record type (one built with cocoindex's schema record mechanism) as record_type
  2. If you have a plain dataclass, convert/declare it as a cocoindex record type first
  3. Ensure you pass the class/type itself, not an instance

Example fix

// before
await DorisTableSchema.from_class(MyDataclass, primary_key=["id"])
// after
await DorisTableSchema.from_class(coco_record_type, primary_key=["id"])
Defensive patterns

Strategy: type-guard

Validate before calling

from cocoindex.resources import schema as _schema
assert _schema.is_record_type(record_type)

Type guard

def is_valid_record_type(rt: object) -> bool:
    from cocoindex.resources import schema as _schema
    return _schema.is_record_type(rt)

Try / catch

try:
    schema = await DorisTableSchema.from_class(record_type, primary_key=pks)
except TypeError as e:
    raise ValueError(f"Bad record_type: {e}") from e

Prevention

When it happens

Trigger: Passing a plain Python class, dataclass, dict, or an instance instead of a cocoindex record type to DorisTableSchema.from_class(record_type=..., primary_key=[...]).

Common situations: Migrating from plain dataclasses/pydantic models without registering them as cocoindex record types; accidentally passing the instantiated record (an instance) rather than the type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08). Data as JSON: /api/errors/0bfc371d977b2c08. Report an issue: GitHub.