{"record":{"id":"db97079413351abd","repo":"pathwaycom/pathway","slug":"batch-size-must-be-a-positive-integer-got-batch","errorCode":null,"errorMessage":"batch_size must be a positive integer, got {batch_size}.","messagePattern":"batch_size must be a positive integer, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/milvus/__init__.py","lineNumber":289,"sourceCode":"    ... )\n\n    Attach the Milvus output connector and specify which column maps to the\n    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 \"","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/milvus/__init__.py#L271-L307","documentation":"pw.io.milvus.write buffers rows into batches of batch_size before upserting. A batch_size below 1 is meaningless (it would never flush), so the connector validates it eagerly at setup and raises ValueError echoing the value you passed.","triggerScenarios":"Passing batch_size=0 (often as an unintentional default from config), a negative number, or a value computed from another variable that evaluates to 0 or below.","commonSituations":"Reading batch_size from env/config where an unset value coerces to 0; arithmetic like len(rows)//N evaluating to 0 for small inputs; copy-paste of an example with a placeholder.","solutions":["Set a positive integer, e.g. batch_size=100 (or simply omit it to use the default)","Validate configuration at startup: batch_size = max(1, int(batch_size)) or assert before building the pipeline","Trace where the value originates — an unset env var or integer division producing 0"],"exampleFix":"# before\npw.io.milvus.write(t, uri, collection_name=\"docs\", primary_key=t.id, batch_size=len(rows)//10)  # 0 for small tables\n\n# after\nbatch_size = max(1, len(rows)//10)\npw.io.milvus.write(t, uri, collection_name=\"docs\", primary_key=t.id, batch_size=batch_size)","handlingStrategy":"validation","validationCode":"batch_size = int(batch_size)\nif batch_size < 1:\n    raise ValueError(f\"batch_size must be >= 1, got {batch_size}\")\n# or normalize: batch_size = max(1, int(batch_size))","typeGuard":"def is_valid_batch_size(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 1","tryCatchPattern":null,"preventionTips":["Validate numeric config values at startup, before building the pipeline","Never derive batch_size from integer division of small inputs without max(1, ...)","Treat 0-valued numeric config as a missing-configuration smell"],"tags":["milvus","pathway","configuration","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}