{"record":{"id":"fac75fb1796fd043","repo":"apache/beam","slug":"invalid-windowing-time-unit-valid-time-units-are","errorCode":null,"errorMessage":"\"Invalid windowing {} time unit '{}'. Valid time units are {}.\"","messagePattern":"\"Invalid windowing (.+?) time unit '(.+?)'\\. Valid time units are (.+?)\\.\"","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_provider.py","lineNumber":1135,"sourceCode":"    def expand(self, pcoll):\n      return pcoll | self._window_transform\n\n    @staticmethod\n    def _parse_duration(value, name):\n      time_units = {\n          'ms': 0.001, 's': 1, 'm': 60, 'h': 60 * 60, 'd': 60 * 60 * 12\n      }\n      value, suffix = re.match(r'^(.*?)([^\\d]*)$', str(value)).groups()\n      # Default to seconds if time unit suffix is not defined\n      if not suffix:\n        suffix = 's'\n      if not value:\n        raise ValueError(\n            f\"Invalid windowing {name} value \"\n            f\"'{suffix if not value else value}'. \"\n            f\"Must provide numeric value.\")\n      if suffix not in time_units:\n        raise ValueError((\n            \"Invalid windowing {} time unit '{}'. \" +\n            \"Valid time units are {}.\").format(\n                name,\n                suffix,\n                ', '.join(\"'{}'\".format(k) for k in time_units.keys())))\n      return float(value) * time_units[suffix]\n\n    @staticmethod\n    def _parse_window_spec(spec):\n      spec = dict(spec)\n      window_type = spec.pop('type')\n      # TODO: These are in seconds, perhaps parse duration strings meaningfully?\n      if window_type == 'global':\n        window_fn = window.GlobalWindows()\n      elif window_type == 'fixed':\n        window_fn = window.FixedWindows(\n            YamlProviders.WindowInto._parse_duration(spec.pop('size'), 'size'),\n            YamlProviders.WindowInto._parse_duration(","sourceCodeStart":1117,"sourceCodeEnd":1153,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_provider.py#L1117-L1153","documentation":"Raised by YamlProviders.WindowInto._parse_duration when the time-unit suffix parsed from a windowing value is not one of the recognized units (the keys of time_units, e.g. s/m/h/d style units). The numeric part parsed fine, but the unit is unknown so the duration cannot be computed.","triggerScenarios":"Passing a windowing duration/gap/offset with an unrecognized unit suffix, e.g. 'gap: 5min', 'gap: 2weeks', 'offset: 10sec' where only 's','m','h','d'-style keys are accepted.","commonSituations":"YAML authors assume full Python timedelta-style units ('min', 'secs', 'weeks') or misspell a unit; defaults are seconds when no suffix is given.","solutions":["Use a supported unit suffix exactly as listed in the error message (e.g. s, m, h, d style keys).","Omit the suffix entirely to get the default of seconds ('5' means 5 seconds).","Convert manually, e.g. '5min' -> '300s' or '2weeks' -> '14d'."],"exampleFix":"# before\ngap: 5min\n# after\ngap: 300s","handlingStrategy":"validation","validationCode":"VALID_UNITS = {'s', 'm', 'h', 'd'}\ndef validate_duration(v):\n    m = re.fullmatch(r'\\s*(\\d+(?:\\.\\d+)?)\\s*([a-zA-Z]*)\\s*', str(v))\n    if not m:\n        raise ValueError(f'Invalid duration {v!r}')\n    unit = m.group(2) or 's'\n    if unit not in VALID_UNITS:\n        raise ValueError(f'Unit {unit!r} not in {sorted(VALID_UNITS)}')","typeGuard":"def has_supported_unit(v, units=('s','m','h','d')):\n    m = re.match(r'^\\d+(?:\\.\\d+)?([^\\d]*)$', str(v).strip())\n    return bool(m) and (m.group(1) in units or m.group(1) == '')","tryCatchPattern":"try:\n    gap = YamlProviders.WindowInto._parse_duration(spec['gap'], 'gap')\nexcept ValueError as e:\n    if 'time unit' in str(e):\n        logging.warning('Unsupported unit, defaulting to seconds: %s', e)\n        gap = float(re.match(r'^(.*?)', str(spec['gap'])).group(1))\n    else:\n        raise","preventionTips":["Use only documented unit suffixes; bare numbers mean seconds.","Convert common aliases manually: min->m*60, week->d*7.","Lint YAML window configs against the accepted unit list.","Centralize duration parsing in one validated helper."],"tags":["python","apache-beam","yaml","windowing"],"backgroundTag":"invalid-duration-format","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"}