{"record":{"id":"9e092e2e6fe82693","repo":"pathwaycom/pathway","slug":"primary-key-column-primary-key-name-r-does-not","errorCode":null,"errorMessage":"primary_key column {primary_key._name!r} does not belong to the provided table. Pass a column reference from the same table, e.g. primary_key=table.{primary_key._name}.","messagePattern":"primary_key column (.+?) does not belong to the provided table\\. Pass a column reference from the same table, e\\.g\\. primary_key=table\\.(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/milvus/__init__.py","lineNumber":292,"sourceCode":"    Milvus primary key field:\n\n    >>> pw.io.milvus.write(   # doctest: +SKIP\n    ...     table,\n    ...     uri=\"./milvus.db\",\n    ...     collection_name=\"docs\",\n    ...     primary_key=table.doc_id,\n    ... )\n    >>> pw.run(monitoring_level=pw.MonitoringLevel.NONE)  # doctest: +SKIP\n    \"\"\"\n    _check_entitlements(\"milvusdb\")\n    with optional_imports(\"milvus\"):\n        from pymilvus import MilvusClient\n\n    if batch_size < 1:\n        raise ValueError(f\"batch_size must be a positive integer, got {batch_size}.\")\n\n    if primary_key._table is not table:\n        raise ValueError(\n            f\"primary_key column {primary_key._name!r} does not belong to the \"\n            f\"provided table. Pass a column reference from the same table, \"\n            f\"e.g. primary_key=table.{primary_key._name}.\"\n        )\n\n    client = _make_client(MilvusClient, uri)\n\n    # Fail fast if the collection is missing: otherwise the error would only\n    # surface deep inside pw.run() on the first upsert, or — for an empty table —\n    # never, silently running a misconfigured pipeline that writes nothing.\n    if not client.has_collection(collection_name):\n        client.close()\n        raise ValueError(\n            f\"Milvus collection {collection_name!r} does not exist; create it \"\n            f\"before writing. pw.io.milvus.write never creates a collection \"\n            f\"because it cannot infer the vector field's dimension.\"\n        )\n","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/milvus/__init__.py#L274-L310","documentation":"The primary_key argument of pw.io.milvus.write must be a ColumnReference bound to the exact table being written. Pathway identity-checks the reference's table and raises ValueError (with a suggested correct form table.<name>) when the reference comes from a different Table instance.","triggerScenarios":"pw.io.milvus.write(base, ..., primary_key=derived.doc_id) where derived is any transform of base (filter/select/with_columns all create new Table objects).","commonSituations":"Reusing a key reference captured before transforms while passing the transformed table, or vice versa; primary keys taken from a join partner table.","solutions":["Pass the final table and its own column together: pw.io.milvus.write(final, ..., primary_key=final.doc_id)","Select the key into the written table if it lives elsewhere: final = t.join(keys, ...).select(..., doc_id=keys.doc_id)","Reference by name defensively: table[table.schema.primary_key_columns()[0]] when wiring dynamically"],"exampleFix":"# before\nready = raw.select(id=raw.doc_id, vec=embed(raw.text))\npw.io.milvus.write(raw, uri, \"docs\", primary_key=ready.id)\n\n# after\nready = raw.select(id=raw.doc_id, vec=embed(raw.text))\npw.io.milvus.write(ready, uri, \"docs\", primary_key=ready.id)","handlingStrategy":"validation","validationCode":"assert primary_key._table is table, (\n    f\"primary_key {primary_key._name!r} not from the written table; \"\n    f\"use table.{primary_key._name}\"\n)","typeGuard":"def pk_from_table(table: pw.Table, col: pw.ColumnReference) -> bool:\n    return col._table is table","tryCatchPattern":"try:\n    pw.io.milvus.write(table, uri, \"docs\", primary_key=primary_key)\nexcept ValueError as e:\n    if \"does not belong to the provided table\" in str(e):\n        primary_key = table[primary_key._name]\n        pw.io.milvus.write(table, uri, \"docs\", primary_key=primary_key)\n    else:\n        raise","preventionTips":["Select the primary key into the final table before wiring the sink","Pass primary_key=final.pk with the same final table variable","Use table[name] lookups in generic connector wrappers"],"tags":["milvus","pathway","column-reference","primary-key","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}