{"record":{"id":"6eabb55525f5d949","repo":"apache/beam","slug":"cannot-interpret-s-s-as-micros","errorCode":null,"errorMessage":"Cannot interpret %s %s as micros.","messagePattern":"Cannot interpret (.+?) (.+?) as micros\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/timestamp.py","lineNumber":98,"sourceCode":"      *,\n      micros: Optional[Union[int, float]] = None) -> None:\n    if not isinstance(seconds, (int, float)):\n      raise TypeError(\n          'Cannot interpret %s %s as seconds.' % (seconds, type(seconds)))\n    if not isinstance(subseconds, (int, float)):\n      raise TypeError(\n          'Cannot interpret %s %s as subseconds.' %\n          (subseconds, type(subseconds)))\n    if not isinstance(precision, int):\n      raise TypeError(\n          'Cannot interpret %s %s as precision.' % (precision, type(precision)))\n    if not 0 <= precision <= Timestamp.NANOS_PRECISION:\n      raise ValueError(\n          'Timestamp precision must be between 0 and %d (inclusive), '\n          'but was %d.' % (Timestamp.NANOS_PRECISION, precision))\n    if micros is not None:\n      if not isinstance(micros, (int, float)):\n        raise TypeError(\n            'Cannot interpret %s %s as micros.' % (micros, type(micros)))\n      if subseconds:\n        raise ValueError(\n            'micros and subseconds are mutually exclusive, got micros=%s, '\n            'subseconds=%s.' % (micros, subseconds))\n      if precision != Timestamp.MICROS_PRECISION:\n        raise ValueError(\n            'micros implies microsecond precision (6) but precision was %d; '\n            'use subseconds instead.' % precision)\n      subseconds = micros\n    self._precision = precision\n    total = int(seconds * _POW_10[precision]) + int(subseconds)\n    self._seconds, self._subseconds = divmod(total, _POW_10[precision])\n\n  def _total(self, precision: int) -> int:\n    \"\"\"Returns the total time since the epoch in units of 10**-precision\n    seconds.\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/timestamp.py#L80-L116","documentation":"When constructing a Timestamp with the `micros` argument, micros must be an int or float. Passing a string (e.g. from config or a parsed token) raises this TypeError. This guard sits inside the `if micros is not None` block of __init__.","triggerScenarios":"Timestamp(micros='1000000') or Timestamp(micros=some_str_from_json); from_utc_datetime passing a non-numeric micros value derived from parsing.","commonSituations":"Reading micros from CSV/JSON where values stay strings; passing Decimal, which is neither int nor float, from a database driver.","solutions":["Convert with int(micros) before constructing","Parse the source value to int at read time (int(json_value))","Validate isinstance(micros, (int, float)) before calling Timestamp"],"exampleFix":"// before\nTimestamp(micros=row['micros'])  # str from CSV\n// after\nTimestamp(micros=int(row['micros']))","handlingStrategy":"type-guard","validationCode":"if micros is not None and not isinstance(micros, (int, float)):\n    micros = int(micros)","typeGuard":"def is_numeric(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Coerce source data (CSV/JSON) to int at ingestion","Avoid Decimal for micros; convert with int(dec)","Keep timestamps as numeric types throughout the pipeline"],"tags":["python","type-error","timestamp"],"backgroundTag":"type-mismatch","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"}