{"record":{"id":"228b1b716fe8b145","repo":"cocoindex-io/cocoindex","slug":"row-is-missing-primary-key-field-self-primary-ke","errorCode":null,"errorMessage":"row is missing primary key field {self._primary_key!r}","messagePattern":"row is missing primary key field (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/falkordb/_target.py","lineNumber":1273,"sourceCode":"    ) -> None:\n        self._provider = provider\n        self._table_schema = table_schema\n        self._table_name = table_name\n        self._primary_key = primary_key\n\n    @property\n    def table_name(self) -> str:\n        return self._table_name\n\n    @property\n    def primary_key(self) -> str:\n        return self._primary_key\n\n    def declare_record(self: TableTarget[RowT], *, row: RowT) -> None:\n        \"\"\"Declare a record (node) to be upserted to this table.\"\"\"\n        row_dict = self._row_to_dict(row)\n        if self._primary_key not in row_dict:\n            raise ValueError(f\"row is missing primary key field {self._primary_key!r}\")\n        pk_values = (row_dict[self._primary_key],)\n        coco.declare_target_state(self._provider.target_state(pk_values, row_dict))\n\n    declare_row = declare_record\n\n    def _row_to_dict(self, row: RowT) -> dict[str, Any]:\n        if self._table_schema is not None:\n            out: dict[str, Any] = {}\n            for col_name, col in self._table_schema.columns.items():\n                if isinstance(row, dict):\n                    value = row.get(col_name)\n                else:\n                    value = getattr(row, col_name)\n                if value is not None and col.encoder is not None:\n                    value = col.encoder(value)\n                out[col_name] = value\n            return out\n        if isinstance(row, dict):","sourceCodeStart":1255,"sourceCodeEnd":1291,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/falkordb/_target.py#L1255-L1291","documentation":"`TableTarget.declare_record` converts the row to a dict and requires the schema's primary key field to be present so it can compute the target-state key. A row lacking that field (after `_row_to_dict`) cannot be keyed/upserted, so ValueError is raised naming the missing field.","triggerScenarios":"Calling `target.declare_record(row=...)` (or `declare_row`) with a row object whose dict form lacks the primary key field — e.g. a dataclass missing the `id` field, or a plain object whose attribute name differs from the schema key.","commonSituations":"Row type drifted from the schema (field renamed); constructing rows ad-hoc in a graph-building function (see callers like `build_graph`, `sync_person_graph`) and forgetting the `id`; a custom row object not matching the declared `row_type`.","solutions":["Ensure every row passed to `declare_record` includes the primary key field with a non-None value.","Align the row class/annotation with the schema's `row_type` so `_row_to_dict` yields the key.","If the key is derived, compute it explicitly before declaring, e.g. `row = Person(id=slug(name), ...)`."],"exampleFix":"// before\ntarget.declare_record(row=Person(name=\"Alice\"))  # schema primary_key=\"id\"\n// after\ntarget.declare_record(row=Person(id=\"alice\", name=\"Alice\"))","handlingStrategy":"validation","validationCode":"row_dict = dataclasses.asdict(row)\nassert schema.primary_key in row_dict and row_dict[schema.primary_key] is not None, \\\n    f\"row missing primary key {schema.primary_key!r}\"\ntarget.declare_record(row=row)","typeGuard":"def has_pk(row: object, pk: str) -> bool:\n    return getattr(row, pk, None) is not None","tryCatchPattern":"try:\n    target.declare_record(row=row)\nexcept ValueError as e:\n    if \"missing primary key field\" in str(e):\n        logging.error(\"Row %r lacks key field; regenerate rows with id set: %s\", row, e)\n    raise","preventionTips":["Make the primary key a required field in the row dataclass (no default).","Construct rows through a factory that always fills the key.","Type row parameters as the schema's RowT so field drift is caught by mypy."],"tags":["python","falkordb","primary-key","target-state"],"backgroundTag":"missing-required-argument","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"}