{"record":{"id":"8a5070c990c05ed8","repo":"cocoindex-io/cocoindex","slug":"primary-key-primary-key-r-does-not-match-the-sch","errorCode":null,"errorMessage":"primary_key {primary_key!r} does not match the schema's declared primary_key {table_schema.primary_key!r}","messagePattern":"primary_key (.+?) does not match the schema's declared primary_key (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/falkordb/_target.py","lineNumber":1435,"sourceCode":"\n# ---------------------------------------------------------------------------\n# Module-level entry points\n# ---------------------------------------------------------------------------\n\n\ndef table_target(\n    db: ContextKey[ConnectionFactory],\n    table_name: str,\n    table_schema: TableSchema[RowT] | None = None,\n    *,\n    primary_key: str = \"id\",\n    managed_by: target.ManagedBy = target.ManagedBy.SYSTEM,\n) -> coco.TargetState[_RecordHandler]:\n    \"\"\"Create a ``TargetState`` for a FalkorDB node table (label).\"\"\"\n    _validate_identifier(table_name, \"table name\")\n    _validate_identifier(primary_key, \"primary key\")\n    if table_schema is not None and table_schema.primary_key != primary_key:\n        raise ValueError(\n            f\"primary_key {primary_key!r} does not match the schema's \"\n            f\"declared primary_key {table_schema.primary_key!r}\"\n        )\n    key = _TableKey(db_key=db.key, table_name=table_name)\n    spec = _TableSpec(\n        table_schema=table_schema,\n        primary_key=primary_key,\n        is_relation=False,\n        from_label=None,\n        from_pk_field=None,\n        to_label=None,\n        to_pk_field=None,\n        managed_by=managed_by,\n    )\n    return _table_provider.target_state(key, spec)\n\n\ndef declare_table_target(","sourceCodeStart":1417,"sourceCodeEnd":1453,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/falkordb/_target.py#L1417-L1453","documentation":"The `table_target` target-state factory validates that the `primary_key` argument matches the `primary_key` recorded in the supplied `TableSchema`. A mismatch would make the keying of target states inconsistent with the schema, so ValueError is raised listing both values.","triggerScenarios":"Calling `falkordb.table_target(db, name, table_schema, primary_key=\"other_key\")` (or via `mount_table_target`) where `primary_key` differs from `table_schema.primary_key`.","commonSituations":"Building the schema with `primary_key=\"doc_id\"` but keeping the default `primary_key=\"id\"` at the target call; two call sites where one was updated after a rename; composing the call programmatically with a stale key variable.","solutions":["Omit `primary_key` so the schema's key is used, or pass `primary_key=table_schema.primary_key`.","Fix the `from_class(..., primary_key=...)` call so both sides agree.","Centralize the key name in one constant used by both schema and target calls."],"exampleFix":"// before\ntable_target(db, \"Doc\", schema, primary_key=\"id\")  # schema.primary_key == \"doc_id\"\n// after\ntable_target(db, \"Doc\", schema)  # defaults to schema.primary_key","handlingStrategy":"validation","validationCode":"if table_schema is not None:\n    assert primary_key == table_schema.primary_key, \\\n        f\"pk mismatch: {primary_key!r} vs schema {table_schema.primary_key!r}\"\ntarget = falkordb.table_target(db, name, table_schema)","typeGuard":null,"tryCatchPattern":"try:\n    target = falkordb.table_target(db, name, table_schema, primary_key=pk)\nexcept ValueError as e:\n    if \"does not match the schema\" in str(e):\n        logging.error(\"Omit primary_key or use table_schema.primary_key: %s\", e)\n    raise","preventionTips":["When a schema is supplied, omit the primary_key argument entirely.","Store the key name once (constant) and reference it in both from_class and table_target.","Cover target construction in a unit test so mismatches fail at test time."],"tags":["python","falkordb","primary-key","consistency"],"backgroundTag":"conflicting-config-options","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"}