{"record":{"id":"09867b982c443b45","repo":"apache/beam","slug":"one-of-topic-or-subscription-may-be-specified","errorCode":null,"errorMessage":"One of topic or subscription may be specified.","messagePattern":"One of topic or subscription may be specified\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_io.py","lineNumber":390,"sourceCode":"      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]))\n    if has_publish_time_field:\n      extra_fields.append(","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_io.py#L372-L408","documentation":"read_from_pubsub got neither 'topic' nor 'subscription'; there is no Pub/Sub endpoint to attach the source to, so the read cannot be constructed. This is the empty-side companion to the topic/subscription mutual-exclusion check.","triggerScenarios":"Calling read_from_pubsub() with both topic=None and subscription=None, e.g. empty YAML keys resolved to None.","commonSituations":"YAML config omits the topic key or a templated variable is empty/unset, silently yielding None.","solutions":["Pass topic='projects/<proj>/topics/<name>'","Or pass subscription='projects/<proj>/subscriptions/<name>'","Verify your config/template substitutes the topic value before invocation"],"exampleFix":"// before\nread_from_pubsub(format='JSON')\n// after\nread_from_pubsub(topic='projects/my-proj/topics/my-topic', format='JSON')","handlingStrategy":"validation","validationCode":"if not topic and not subscription:\n    raise ValueError('Provide either topic or subscription')","typeGuard":"def has_read_source(args):\n    return bool(args.get('topic') or args.get('subscription'))","tryCatchPattern":"try:\n    read_from_pubsub(topic=cfg.get('topic'), subscription=cfg.get('subscription'))\nexcept TypeError as e:\n    if 'One of topic' in str(e):\n        log.error('Configure a Pub/Sub topic or subscription')\n        raise","preventionTips":["Fail fast on empty config values before pipeline construction","Use required-field checks when loading YAML","Avoid Optional defaults of None for source identifiers"],"tags":["python","apache-beam","pubsub","missing-required-argument"],"backgroundTag":"missing-required-argument","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"}