{"record":{"id":"8a73196b13587c1b","repo":"pathwaycom/pathway","slug":"you-can-t-use-the-same-connectorsubject-object-in","errorCode":null,"errorMessage":"You can't use the same ConnectorSubject object in more than one Python connector.If you want to use the same ConnectorSubject twice, create two separate objects of this class.","messagePattern":"You can't use the same ConnectorSubject object in more than one Python connector\\.If you want to use the same ConnectorSubject twice, create two separate objects of this class\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/python/__init__.py","lineNumber":600,"sourceCode":"    >>> pw.debug.compute_and_print(table, include_id=False)\n    a | b\n    0 | x0\n    1 | x1\n    2 | x2\n    3 | x3\n    \"\"\"\n\n    if format is None:\n        format = \"json\"  # previous default\n    else:\n        warnings.warn(\n            \"Setting `format` in Python connector is deprecated.\"\n            + \" Please just pass values of proper types to the `next` method.\",\n            DeprecationWarning,\n        )\n\n    if subject._already_used:\n        raise ValueError(\n            \"You can't use the same ConnectorSubject object in more than one Python connector.\"\n            + \"If you want to use the same ConnectorSubject twice, create two separate objects of this class.\"\n        )\n    subject._already_used = True\n    subject._pw_format = format\n\n    data_format_type = get_data_format_type(format, SUPPORTED_INPUT_FORMATS)\n\n    if data_format_type == \"identity\":\n        if format == \"binary\":\n            schema = RawDataSchema\n        else:\n            schema = PlaintextDataSchema\n        if subject._with_metadata is True:\n            schema |= MetadataSchema\n\n    schema = assert_schema_not_none(schema, data_format_type)\n    return table_from_datasource(","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/python/__init__.py#L582-L618","documentation":"Raised by pw.io.python.read when the ConnectorSubject instance passed in has already been used by another Python connector (guarded by an internal _already_used flag). Subjects carry per-connector runtime state, so sharing one object across two reads would interleave buffers and lifecycle callbacks; Pathway requires a fresh instance per connector.","triggerScenarios":"Reusing a module-level subject instance: subject = MySubject(); pw.io.python.read(subject, schema=S1, ...); pw.io.python.read(subject, schema=S2, ...) in the same process (including two branches of one pipeline).","commonSituations":"Fan-out patterns where the same upstream feed should feed two tables; refactorings that hoist subject creation to module scope for reuse; test suites that build pipelines in a loop with a shared fixture subject without resetting between cases.","solutions":["Instantiate a new subject per connector: pw.io.python.read(MySubject(), schema=S1, ...); pw.io.python.read(MySubject(), schema=S2, ...).","If the source is genuinely shared, read it once into one table and fork with Pathway table operations (select/filter/join) instead of two connectors.","In tests, create the subject inside the test/fixture function rather than at module level."],"exampleFix":"# before\nsubject = MySubject()\npw.io.python.read(subject, schema=S1)\npw.io.python.read(subject, schema=S2)  # ValueError\n\n# after\npw.io.python.read(MySubject(), schema=S1)\npw.io.python.read(MySubject(), schema=S2)","handlingStrategy":"validation","validationCode":"pw.io.python.read(MySubject(), schema=S1)   # fresh instance each time\npw.io.python.read(MySubject(), schema=S2)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hoist a ConnectorSubject to module scope for reuse.","Fan out with table operations after a single read, not with two connectors over one subject.","Create subjects inside fixtures/functions in tests."],"tags":["pathway","python-connector","api-misuse","shared-state"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}