{"record":{"id":"d64eda52af50139f","repo":"apache/beam","slug":"only-one-of-topic-or-subscription-should-be-provided","errorCode":null,"errorMessage":"Only one of topic or subscription should be provided.","messagePattern":"Only one of topic or subscription should be provided\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/pubsub.py","lineNumber":540,"sourceCode":"      topic: Optional[str] = None,\n      subscription: Optional[str] = None,\n      id_label: Optional[str] = None,\n      with_attributes: bool = False,\n      timestamp_attribute: Optional[str] = None):\n    self.coder = coders.BytesCoder()\n    self.full_topic = topic\n    self.full_subscription = subscription\n    self.topic_name = None\n    self.subscription_name = None\n    self.id_label = id_label\n    self.with_attributes = with_attributes\n    self.timestamp_attribute = timestamp_attribute\n\n    # Perform some validation on the topic and subscription.\n    if not (topic or subscription):\n      raise ValueError('Either a topic or subscription must be provided.')\n    if topic and subscription:\n      raise ValueError('Only one of topic or subscription should be provided.')\n\n    if topic:\n      self.project, self.topic_name = parse_topic(topic)\n    if subscription:\n      self.project, self.subscription_name = parse_subscription(subscription)\n\n  def display_data(self):\n    return {\n        'id_label': DisplayDataItem(self.id_label,\n                                    label='ID Label Attribute').drop_if_none(),\n        'topic': DisplayDataItem(self.full_topic,\n                                 label='Pubsub Topic').drop_if_none(),\n        'subscription': DisplayDataItem(\n            self.full_subscription, label='Pubsub Subscription').drop_if_none(),\n        'with_attributes': DisplayDataItem(\n            self.with_attributes, label='With Attributes').drop_if_none(),\n        'timestamp_attribute': DisplayDataItem(\n            self.timestamp_attribute,","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/pubsub.py#L522-L558","documentation":"The PubSub source constructor validates that exactly one of 'topic' or 'subscription' is provided; here the mutual-exclusion check found both supplied (the companion check fires when neither is), because a read cannot be bound to two endpoints at once.","triggerScenarios":"ReadFromPubSub(topic=..., subscription=...) with both non-None; config merging where defaults for topic and an explicit subscription coexist.","commonSituations":"Copy-paste code leaving both arguments populated; combining a default topic with an override subscription from two config layers; misunderstanding that both can be given for flexibility.","solutions":["Supply only one of topic or subscription","If both config values exist, choose one explicitly (e.g. prefer subscription) and drop the other","Unify configuration so a single key determines the source"],"exampleFix":"// before\nReadFromPubSub(topic='projects/p/topics/t', subscription='projects/p/subscriptions/s')\n// after\nReadFromPubSub(subscription='projects/p/subscriptions/s')","handlingStrategy":"validation","validationCode":"assert not (topic and subscription), 'pass only one of topic or subscription'","typeGuard":null,"tryCatchPattern":"try:\n    beam.io.ReadFromPubSub(topic=topic, subscription=subscription)\nexcept ValueError as e:\n    if 'Only one of topic or subscription' in str(e):\n        topic = None  # prefer subscription\n    else:\n        raise","preventionTips":["Use a single source-kind config key ('kind': topic|subscription) with one path field","Validate exclusivity at config load, before building the transform","Document that topic and subscription are mutually exclusive"],"tags":["python","pubsub","validation","apache-beam"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}