{"record":{"id":"c2519a61b86e8be2","repo":"apache/beam","slug":"bad-timestamp-value-s","errorCode":null,"errorMessage":"Bad timestamp value: %s","messagePattern":"Bad timestamp value: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/direct/transform_evaluator.py","lineNumber":726,"sourceCode":"  def process_element(self, element):\n    pass\n\n  def _read_from_pubsub(\n      self, timestamp_attribute) -> list[tuple[Timestamp, 'PubsubMessage']]:\n    from apache_beam.io.gcp.pubsub import PubsubMessage\n\n    def _get_element(message):\n      parsed_message = PubsubMessage._from_message(message)\n      if (timestamp_attribute and\n          timestamp_attribute in parsed_message.attributes):\n        rfc3339_or_milli = parsed_message.attributes[timestamp_attribute]\n        try:\n          timestamp = Timestamp(micros=int(rfc3339_or_milli) * 1000)\n        except ValueError:\n          try:\n            timestamp = Timestamp.from_rfc3339(rfc3339_or_milli)\n          except ValueError as e:\n            raise ValueError('Bad timestamp value: %s' % e)\n        if timestamp.precision() > Timestamp.MICROS_PRECISION:\n          # Element timestamps are limited to microsecond resolution, so\n          # ignore sub-microsecond digits, as the Dataflow service does.\n          timestamp = timestamp.to_precision(\n              Timestamp.MICROS_PRECISION, allow_lossy_conversion=True)\n      else:\n        if message.publish_time is None:\n          raise ValueError('No publish time present in message: %s' % message)\n        try:\n          timestamp = Timestamp.from_utc_datetime(message.publish_time)\n        except ValueError as e:\n          raise ValueError('Bad timestamp value for message %s: %s', message, e)\n\n      return timestamp, parsed_message\n\n    # Because of the AutoAck, we are not able to reread messages if this\n    # evaluator fails with an exception before emitting a bundle. However,\n    # the DirectRunner currently doesn't retry work items anyway, so the","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/direct/transform_evaluator.py#L708-L744","documentation":"When parsing a Pub/Sub message attribute (timestamp_attribute), the evaluator first tries to interpret the value as milliseconds since epoch, then as RFC 3339. If both parses fail, it re-raises as ValueError('Bad timestamp value: ...') wrapping the original error.","triggerScenarios":"A Pub/Sub message whose timestamp_attribute value is neither an integer/numeric millisecond string nor a valid RFC 3339 timestamp (e.g. 'yesterday', '2024/01/01', empty string) while reading with timestamp_attribute set.","commonSituations":"Publisher writes human-readable dates or localized formats into the attribute; attribute accidentally empty; timezone-omitted timestamps ('2024-01-01 12:00:00') that aren't RFC 3339.","solutions":["Publish attributes as RFC 3339 UTC strings, e.g. '2024-01-01T12:00:00Z', or integer milliseconds since epoch.","Use Python: datetime.now(timezone.utc).isoformat() or similar when publishing.","Validate/scrub the attribute at publish time; drop or default invalid values.","Confirm the correct attribute name is passed to timestamp_attribute (a wrong attribute may surface unrelated data)."],"exampleFix":"// before\nmsg['event_time'] = '2024-01-01 12:00:00'\n// after\nmsg['event_time'] = '2024-01-01T12:00:00Z'","handlingStrategy":"validation","validationCode":"import re\nRFC3339 = re.compile(r'^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$')\nMILLIS = re.compile(r'^\\d+$')\nassert RFC3339.match(attr) or MILLIS.match(attr), f'bad timestamp_attribute value: {attr!r}'","typeGuard":"def is_valid_event_time_attr(value: str) -> bool:\n    import re\n    return bool(re.fullmatch(r'\\d+', value)) or _is_rfc3339(value)","tryCatchPattern":"try:\n    pipeline.run()\nexcept ValueError as e:\n    if 'Bad timestamp value' in str(e):\n        log_publisher_schema_violation(e)","preventionTips":["Standardize publisher timestamps on RFC 3339 UTC or epoch millis.","Add publisher-side schema validation for the timestamp attribute.","Never publish human-formatted dates into machine-read attributes."],"tags":["python","apache-beam","pubsub","timestamp"],"backgroundTag":"invalid-date-format","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"}