{"record":{"id":"0023181661c05881","repo":"apache/beam","slug":"only-one-of-topic-and-subscription-may-be-specified","errorCode":null,"errorMessage":"Only one of topic and subscription may be specified.","messagePattern":"Only one of topic and subscription may be specified\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_io.py","lineNumber":388,"sourceCode":"      deduplication of messages. If not provided, we cannot guarantee\n      that no duplicate data will be delivered on the Pub/Sub stream. In this\n      case, deduplication of the stream will be strictly best effort.\n    timestamp_attribute: Message value to use as element timestamp. If None,\n      uses message publishing time as the timestamp.\n\n      Timestamp values should be in one of two formats:\n\n      - A numerical value representing the number of milliseconds since the\n        Unix epoch.\n      - A string in RFC 3339 format, UTC timezone. Example:\n        ``2015-10-29T23:41:41.123Z``. The sub-second component of the\n        timestamp is optional, and digits beyond the first three (i.e., time\n        units smaller than milliseconds) may be ignored.\n    publish_time_field: Field to add to output messages with the Pub/Sub\n      message publish time. If None, no such field is added.\n  \"\"\"\n  if topic and subscription:\n    raise TypeError('Only one of topic and subscription may be specified.')\n  elif not topic and not subscription:\n    raise TypeError('One of topic or subscription may be specified.')\n  if publish_time_field is not None and not publish_time_field.strip():\n    raise ValueError('publish_time_field must be a non-empty field name.')\n  has_publish_time_field = publish_time_field is not None\n  payload_schema, parser = _create_parser(format, schema)\n  extra_fields: list[schema_pb2.Field] = []\n  if not attributes and not attributes_map and not has_publish_time_field:\n    mapper = lambda msg: parser(msg)\n  else:\n    if isinstance(attributes, str):\n      attributes = [attributes]\n    if attributes:\n      extra_fields.extend(\n          [schemas.schema_field(attr, str) for attr in attributes])\n    if attributes_map:\n      extra_fields.append(\n          schemas.schema_field(attributes_map, Mapping[str, str]))","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_io.py#L370-L406","documentation":"read_from_pubsub validates its arguments: both 'topic' and 'subscription' were given, but a Pub/Sub read binds to exactly one of them; the guard fires at graph construction before any subscription is created.","triggerScenarios":"Calling read_from_pubsub(topic=..., subscription=...) with both arguments truthy.","commonSituations":"Config templating fills in both keys; users paste a subscription path while also keeping the topic argument from earlier config.","solutions":["Specify only the subscription (it already determines the topic)","Or specify only the topic to let Beam create/use an ephemeral path","Remove the redundant key from your YAML/config before calling"],"exampleFix":"// before\nread_from_pubsub(topic='projects/p/topics/t', subscription='projects/p/subs/s')\n// after\nread_from_pubsub(subscription='projects/p/subs/s')","handlingStrategy":"validation","validationCode":"if bool(topic) and bool(subscription):\n    raise ValueError('Pass only one of topic or subscription')","typeGuard":null,"tryCatchPattern":"try:\n    read_from_pubsub(topic=t, subscription=s)\nexcept TypeError as e:\n    if 'Only one of topic' in str(e):\n        read_from_pubsub(subscription=s)","preventionTips":["Prefer subscription-only config for durable reads","Sanitize templated config so stale keys do not persist","Validate mutually exclusive args at config load time"],"tags":["python","apache-beam","pubsub","conflicting-options"],"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"}