{"record":{"id":"3a6ad0a7c36939c8","repo":"apache/beam","slug":"publish-time-field-must-be-a-non-empty-field-name","errorCode":null,"errorMessage":"publish_time_field must be a non-empty field name.","messagePattern":"publish_time_field must be a non-empty field name\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_io.py","lineNumber":392,"sourceCode":"      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(\n          schemas.schema_field(publish_time_field, Optional[Timestamp]))\n","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_io.py#L374-L410","documentation":"read_from_pubsub validates publish_time_field: it must be a non-empty field name because it becomes a column on each output Row carrying the message's publish time; an empty string would create an unnamed, unqueryable field.","triggerScenarios":"publish_time_field='' or '   ' passed to read_from_pubsub (is not None passes, but .strip() is empty).","commonSituations":"YAML key publish_time_field: '' left empty after editing config; user intends to disable it but leaves an empty string instead of removing the key.","solutions":["Remove the publish_time_field key entirely to disable it","Or provide an actual field name like publish_time","Strip/sanitize the config value before passing it"],"exampleFix":"// before\npublish_time_field: ''\n// after\npublish_time_field: publish_time","handlingStrategy":"validation","validationCode":"if publish_time_field is not None and not publish_time_field.strip():\n    publish_time_field = None  # or raise","typeGuard":"def is_valid_field_name(name):\n    return isinstance(name, str) and bool(name.strip())","tryCatchPattern":"try:\n    read_from_pubsub(..., publish_time_field=ptf)\nexcept ValueError as e:\n    if 'non-empty field name' in str(e):\n        ptf = None  # disable the feature","preventionTips":["Omit the key entirely to disable, never set it to ''","Strip config strings before use","Treat empty-string configs as absent during normalization"],"tags":["python","apache-beam","pubsub","validation"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}