{"record":{"id":"0fcb987826606350","repo":"apache/beam","slug":"unrecognized-unit","errorCode":null,"errorMessage":"Unrecognized unit.","messagePattern":"Unrecognized unit\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/resources.py","lineNumber":138,"sourceCode":"        'PiB': 2**50,\n        'TiB': 2**40,\n        'GiB': 2**30,\n        'MiB': 2**20,\n        'KiB': 2**10,\n        'PB': 10**15,\n        'TB': 10**12,\n        'GB': 10**9,\n        'MB': 10**6,\n        'KB': 10**3,\n        'B': 1,\n    }\n    match = re.match(r'.*?(\\D+)$', value)\n    if not match:\n      raise ValueError(\"Unrecognized value pattern.\")\n\n    suffix = match.group(1)\n    if suffix not in units:\n      raise ValueError(\"Unrecognized unit.\")\n    multiplier = units[suffix]\n    value = value[:-len(suffix)]\n\n    return str(round(float(value) * multiplier)).encode('ascii')\n\n  @staticmethod\n  def _use_max(v1, v2):\n    return str(max(int(v1), int(v2))).encode('ascii')\n\n  @staticmethod\n  def _use_sum(v1, v2):\n    return str(int(v1) + int(v2)).encode('ascii')\n\n\nclass AcceleratorHint(ResourceHint):\n  \"\"\"Describes desired hardware accelerators in execution environment.\"\"\"\n  urn = resource_hints.ACCELERATOR.urn\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/resources.py#L120-L156","documentation":"After extracting the trailing non-digit suffix of a storage size string, _parse_storage_size_str checks it against a fixed unit table ('TB','GB','MB','KB','B'). A suffix not in that table is rejected with this error. Units like 'MiB', 'GiB' or 'm' are not accepted.","triggerScenarios":"Passing a hint value such as '512MiB', '4G', or '2mb' (case-sensitive lookup) to a storage resource hint; parse succeeds on the regex but the suffix is absent from the units dict.","commonSituations":"Mixing binary prefixes (MiB/GiB) with Beam's decimal units (MB/GB); lowercase unit spellings; inventing units like 'TBs' or 'gigabytes'.","solutions":["Use exactly one of the supported units: TB, GB, MB, KB, B (correct case, no plural).","Convert binary units manually: 512MiB -> '536870912B' or approximately '537MB'.","Normalize/strip the value of whitespace before passing it, e.g. ' 512MB ' -> '512MB' if stray spaces cause a bad suffix."],"exampleFix":"// before\nadd_resource_hint('storage=2GiB')\n// after\nadd_resource_hint('storage=2GB')","handlingStrategy":"validation","validationCode":"UNITS = {'TB', 'GB', 'MB', 'KB', 'B'}\nsuffix = re.search(r'(\\D+)$', value).group(1) if re.search(r'\\D+$', value) else ''\nassert suffix in UNITS, f\"{value!r}: unit {suffix!r} not in {UNITS}\"","typeGuard":"def has_supported_unit(value: str) -> bool:\n    m = re.search(r'(\\D+)$', value)\n    return m is not None and m.group(1) in {'TB','GB','MB','KB','B'}","tryCatchPattern":"try:\n    hints = parse_resource_hints(raw_hints)\nexcept ValueError as e:\n    if 'Unrecognized unit' in str(e):\n        raw_hints = {k: normalize_unit(v) for k, v in raw_hints.items()}\n        hints = parse_resource_hints(raw_hints)","preventionTips":["Use only Beam's decimal units: TB, GB, MB, KB, B (case-sensitive, no binary MiB/GiB).","Write a normalize_unit helper converting MiB->B before passing hints.","Strip whitespace from hint values."],"tags":["python","apache-beam","resource-hints","invalid-unit"],"backgroundTag":"invalid-enum-value","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"}