{"record":{"id":"a78e1854757be835","repo":"apache/beam","slug":"cannot-interpret-s-s-as-precision","errorCode":null,"errorMessage":"Cannot interpret %s %s as precision.","messagePattern":"Cannot interpret (.+?) (.+?) as precision\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/timestamp.py","lineNumber":90,"sourceCode":"  MICROS_PRECISION = 6\n  NANOS_PRECISION = 9\n\n  def __init__(\n      self,\n      seconds: Union[int, float] = 0,\n      subseconds: Union[int, float] = 0,\n      precision: int = MICROS_PRECISION,\n      *,\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","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/timestamp.py#L72-L108","documentation":"Timestamp.__init__ validates that the `precision` argument is an integer. If you pass precision as a float, string, or None, a TypeError is raised because precision must be a whole count of fractional digits (0-9). The library throws this to fail fast before computing nanosecond-resolution values with an invalid precision type.","triggerScenarios":"Calling Timestamp(seconds=..., precision='6') or precision=6.0 or precision=None directly or via from_rfc3339-style helpers that pass a non-int precision.","commonSituations":"Parsing precision from JSON/YAML config where numbers deserialize as floats or strings; passing len(fraction_digits) from a string as str; arithmetic like precision//2 in Python 2 producing floats.","solutions":["Pass precision as a Python int, e.g. Timestamp(seconds=1.5, precision=6)","Coerce with int(): Timestamp(..., precision=int(precision))","If parsing from config, validate the value with isinstance(precision, int) first"],"exampleFix":"// before\nTimestamp(seconds=1.5, precision=float(cfg.precision))\n// after\nTimestamp(seconds=1.5, precision=int(cfg.precision))","handlingStrategy":"validation","validationCode":"if not isinstance(precision, int) or not 0 <= precision <= 9:\n    raise ValueError(f'precision must be int in [0,9], got {precision!r}')","typeGuard":"def is_valid_precision(p) -> bool:\n    return isinstance(p, int) and 0 <= p <= Timestamp.NANOS_PRECISION","tryCatchPattern":null,"preventionTips":["Never compute precision with float arithmetic; use int literals or //","Validate config-derived precision types at load time","Coerce numeric config strings with int() once at parse boundary"],"tags":["python","type-error","timestamp"],"backgroundTag":"invalid-constructor-argument","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"}