{"record":{"id":"db5b8c330735c743","repo":"apache/pulsar","slug":"partitioned-topic-is-not-available-in-effectively","errorCode":null,"errorMessage":"Partitioned topic is not available in effectively_once mode.","messagePattern":"Partitioned topic is not available in effectively_once mode\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"pulsar-functions/instance/src/main/python/python_instance.py","lineNumber":325,"sourceCode":"      if self.auto_ack and self.atleast_once or self.effectively_once:\n        consumer.acknowledge(orig_message)\n    else:\n      error_msg = \"Failed to publish to topic [%s] with error [%s] with src message id [%s]\" % (topic, result, orig_message.message_id())\n      Log.error(error_msg)\n      self.stats.incr_total_sys_exceptions(Exception(error_msg))\n      # If producer fails send output then send neg ack for input message back to broker\n      consumer.negative_acknowledge(orig_message)\n\n  def process_result(self, output, msg):\n    if output is not None and self.instance_config.function_details.sink.topic is not None and \\\n            len(self.instance_config.function_details.sink.topic) > 0:\n      if self.output_serde is None:\n        self.setup_output_serde()\n      if self.effectively_once:\n        if self.contextimpl.get_message_partition_index() is None or \\\n                self.contextimpl.get_message_partition_index() >= 0:\n          Log.error(\"Partitioned topic is not available in effectively_once mode.\")\n          raise Exception(\"Partitioned topic is not available in effectively_once mode.\")\n\n        producer_id = self.instance_config.function_details.sink.topic\n        producer = self.contextimpl.publish_producers.get(producer_id)\n        if producer is None:\n          self.setup_producer(producer_name=producer_id)\n          self.contextimpl.publish_producers[producer_id] = self.producer\n          Log.info(\"Setup producer [%s] successfully in effectively_once mode.\" % self.producer.producer_name())\n\n      if self.producer is None:\n        self.setup_producer()\n        Log.info(\"Setup producer successfully.\")\n\n      # only serialize function output when output schema is not set\n      output_object = output\n      if self.output_schema == DEFAULT_SCHEMA:\n        output_object = self.output_serde.serialize(output)\n\n      if output_object is not None:","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/instance/src/main/python/python_instance.py#L307-L343","documentation":"In effectively-once mode, python_instance.process_result publishes results through a producer keyed by the configured sink topic and relies on the message's partition index being negative (i.e. a non-partitioned topic) for dedup guarantees. If get_message_partition_index() is None or >= 0, Pulsar raises Exception('Partitioned topic is not available in effectively_once mode.') because effectively-once delivery isn't supported over a partitioned output topic in this path.","triggerScenarios":"Running a Python function with effectivelyOnce=true while the input message comes from a partitioned topic (partition index >= 0) or the index is unavailable (None) — checked in process_result during actual_execution of a normal (non-batch) message.","commonSituations":"Enabling effectively-once for a function whose input topic is partitioned; upgrading/adding effectivelyOnce config to an existing function consuming partitioned topics; missing message metadata yielding None partition index.","solutions":["Disable effectivelyOnce if the input topic is partitioned.","Use a non-partitioned input topic when effectively-once semantics are required.","Ensure the message carries a valid (negative, non-partitioned) partition index; check producer/topic setup upstream.","Restructure so effectively-once publishing targets a non-partitioned sink topic."],"exampleFix":"# before (function config)\neffectivelyOnce: true  # input topic my-topic has 4 partitions\n# after\neffectivelyOnce: false\n# or consume from non-partitioned 'my-topic-non-partitioned'","handlingStrategy":"validation","validationCode":"if effectively_once and (msg.partition_index() is None or msg.partition_index() >= 0):\n    raise RuntimeError('effectively-once requires a non-partitioned input topic')","typeGuard":null,"tryCatchPattern":"try:\n    process(msg)\nexcept Exception as e:\n    if 'effectively_once' in str(e):\n        logging.error('disable effectivelyOnce or use non-partitioned topic')","preventionTips":["Don't enable effectivelyOnce for partitioned input topics.","Confirm partition index metadata is present on messages.","Document the effectively-once topic constraint in your function config review checklist."],"tags":["python","pulsar-functions","effectively-once","partitioned-topic"],"backgroundTag":"partitioned-topic-unsupported","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}