{"record":{"id":"f67a8980f017608e","repo":"apache/beam","slug":"could-not-parse-rfc-3339-string-s-fractional-seconds-beyond","errorCode":null,"errorMessage":"Could not parse RFC 3339 string '%s': fractional seconds beyond nanosecond precision are not supported.","messagePattern":"Could not parse RFC 3339 string '(.+?)': fractional seconds beyond nanosecond precision are not supported\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/utils/timestamp.py","lineNumber":201,"sourceCode":"      All timezones are implicitly converted to UTC.\n\n    Args:\n      rfc3339: String in RFC 3339 form.\n    \"\"\"\n    try:\n      dt = dateutil.parser.isoparse(rfc3339).astimezone(pytz.UTC)\n    except ValueError as e:\n      raise ValueError(\n          \"Could not parse RFC 3339 string '{}' due to error: '{}'.\".format(\n              rfc3339, e))\n    timestamp = cls.from_utc_datetime(dt)\n    # dateutil silently truncates fractional seconds to microseconds; parse\n    # any sub-microsecond digits ourselves to avoid losing precision.\n    fraction = re.search(r'[0-9]{2}[.,]([0-9]{7,})', rfc3339)\n    if fraction:\n      digits = fraction.group(1)\n      if len(digits) > cls.NANOS_PRECISION:\n        raise ValueError(\n            \"Could not parse RFC 3339 string '%s': fractional seconds \"\n            'beyond nanosecond precision are not supported.' % rfc3339)\n      precision = len(digits)\n      sub_micro = int(digits[cls.MICROS_PRECISION:])\n      return Timestamp(\n          timestamp.seconds(),\n          timestamp.subseconds() * _POW_10[precision - cls.MICROS_PRECISION] +\n          sub_micro,\n          precision)\n    return timestamp\n\n  def seconds(self) -> int:\n    \"\"\"Returns the timestamp in seconds.\"\"\"\n    return self._seconds\n\n  def subseconds(self) -> int:\n    \"\"\"Returns the fraction of a second, in units of 10**-precision seconds.\n","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/utils/timestamp.py#L183-L219","documentation":"After isoparse succeeds, from_rfc3339() scans the raw string for fractional-second digits; if more than NANOS_PRECISION (9) digits are present (sub-nanosecond), the value cannot be represented and a ValueError is raised rather than silently losing precision.","triggerScenarios":"Timestamp.from_rfc3339('2024-01-01T00:00:00.123456789012Z') — 12 fractional digits exceed nanosecond precision.","commonSituations":"Ingesting scientific/instrument timestamps with picosecond or femtosecond fractions; concatenating a performance-counter suffix onto an RFC 3339 string; Java Instant or chrono APIs emitting >9 digits.","solutions":["Truncate the fractional part to at most 9 digits before parsing: s[:idx+10]","Round the value to nanoseconds and reconstruct the string","If full fidelity is needed, keep the extra digits in a separate field and parse only the first 9 with from_rfc3339"],"exampleFix":"// before\nts = Timestamp.from_rfc3339('2024-01-01T00:00:00.123456789012Z')\n// after\nm = re.match(r'(.*\\.\\d{9})\\d+', s)\nts = Timestamp.from_rfc3339(m.group(1) + 'Z') if m else Timestamp.from_rfc3339(s)","handlingStrategy":"validation","validationCode":"m = re.search(r'[.,](\\d+)', s)\nif m and len(m.group(1)) > 9:\n    s = re.sub(r'([.,]\\d{9})\\d+', r'\\1', s)","typeGuard":null,"tryCatchPattern":"try:\n    ts = Timestamp.from_rfc3339(s)\nexcept ValueError as e:\n    if 'beyond nanosecond' in str(e):\n        ts = Timestamp.from_rfc3339(re.sub(r'([.,]\\d{9})\\d+', r'\\1', s))\n    else:\n        raise","preventionTips":["Truncate fractional seconds to 9 digits at ingestion","Do not append raw counter digits to RFC 3339 strings","Store sub-nanosecond remainder in a separate field if needed"],"tags":["python","value-error","timestamp","rfc3339","precision"],"backgroundTag":"value-out-of-range","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"}