{"record":{"id":"760921c59bdae787","repo":"apache/beam","slug":"cannot-interpret-s-s-as-timestamp","errorCode":null,"errorMessage":"Cannot interpret %s %s as Timestamp.","messagePattern":"Cannot interpret (.+?) (.+?) as Timestamp\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/timestamp.py","lineNumber":143,"sourceCode":"    \"\"\"Return the Timestamp for the given number of seconds.\n\n    If the input is already a Timestamp, the input itself will be returned.\n\n    Args:\n      seconds: Number of seconds as int, float, long, or Timestamp.\n\n    Returns:\n      Corresponding Timestamp object.\n    \"\"\"\n\n    if isinstance(seconds, Timestamp):\n      return seconds\n    elif isinstance(seconds, (int, float)):\n      return Timestamp(seconds)\n    elif isinstance(seconds, datetime.datetime):\n      return Timestamp.from_utc_datetime(seconds)\n    else:\n      raise TypeError(\n          'Cannot interpret %s %s as Timestamp.' % (seconds, type(seconds)))\n\n  @staticmethod\n  def now() -> 'Timestamp':\n    return Timestamp(seconds=time.time())\n\n  @staticmethod\n  def _epoch_datetime_utc() -> datetime.datetime:\n    return datetime.datetime.fromtimestamp(0, pytz.utc)\n\n  @classmethod\n  def from_utc_datetime(cls, dt: datetime.datetime) -> 'Timestamp':\n    \"\"\"Create a ``Timestamp`` instance from a ``datetime.datetime`` object.\n\n    Args:\n      dt: A ``datetime.datetime`` object in UTC (offset-aware).\n    \"\"\"\n    if dt.tzinfo is None:","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/timestamp.py#L125-L161","documentation":"Timestamp.of() accepts a Timestamp, int/float seconds, or a datetime.datetime; anything else (string, None, Decimal, etc.) raises this TypeError. It is the coercion entry point, so it reports the value and its type to make the bad input obvious.","triggerScenarios":"Timestamp.of('2024-01-01T00:00:00Z') — strings are NOT parsed; Timestamp.of(None) from an upstream missing value; Timestamp.of(decimal.Decimal(1.5)).","commonSituations":"Assuming Timestamp.of parses RFC 3339 strings (use of_rfc3339/from_rfc3339 instead); passing Optional values straight from a dict/protobuf without a None check; handing in numpy types in edge cases.","solutions":["Parse strings first: Timestamp.of_rfc3339(s) or Timestamp.from_rfc3339(s)","Convert to int/float seconds or datetime.datetime before calling","Check for None and supply a default Timestamp.now() or skip the record"],"exampleFix":"// before\nTimestamp.of(row['event_time'])  # str\n// after\nts = Timestamp.of_rfc3339(row['event_time'])","handlingStrategy":"type-guard","validationCode":"if value is None:\n    raise ValueError('event time missing')\nif isinstance(value, str):\n    value = Timestamp.from_rfc3339(value)","typeGuard":"def is_timestamp_coercible(v) -> bool:\n    return isinstance(v, (Timestamp, int, float, datetime.datetime))","tryCatchPattern":"try:\n    ts = Timestamp.of(value)\nexcept TypeError:\n    ts = Timestamp.of_rfc3339(str(value))","preventionTips":["Never assume Timestamp.of parses strings; use of_rfc3339/from_rfc3339","Check for None from upstream sources before coercion","Convert Decimal/numpy scalars to int/float first"],"tags":["python","type-error","timestamp"],"backgroundTag":"incompatible-source-type","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"}