{"record":{"id":"1960695205569541","repo":"apache/beam","slug":"input-must-be-an-integer","errorCode":null,"errorMessage":"Input must be an integer.","messagePattern":"Input must be an integer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/resources.py","lineNumber":105,"sourceCode":"  @staticmethod\n  def register_resource_hint(hint_name: str, hint_class: type) -> None:\n    assert issubclass(hint_class, ResourceHint)\n    assert hint_class.urn is not None\n    ResourceHint._name_to_known_hints[hint_name] = hint_class\n    ResourceHint._urn_to_known_hints[hint_class.urn] = hint_class\n\n  @staticmethod\n  def _parse_str(value):\n    if not isinstance(value, str):\n      raise ValueError(\"Input must be a string.\")\n    return value.encode('ascii')\n\n  @staticmethod\n  def _parse_int(value):\n    if isinstance(value, str):\n      value = int(value)\n    if not isinstance(value, int):\n      raise ValueError(\"Input must be an integer.\")\n    return str(value).encode('ascii')\n\n  @staticmethod\n  def _parse_storage_size_str(value):\n    \"\"\"Parses a human-friendly storage size string into a number of bytes.\n    \"\"\"\n    if isinstance(value, int):\n      return ResourceHint._parse_int(value)\n\n    if not isinstance(value, str):\n      raise ValueError(\"Input must be a string or integer.\")\n\n    value = value.strip().replace(\" \", \"\")\n    units = {\n        'PiB': 2**50,\n        'TiB': 2**40,\n        'GiB': 2**30,\n        'MiB': 2**20,","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/resources.py#L87-L123","documentation":"ResourceHint's `_parse_int` accepts either an int or a decimal string (strings are converted via int()); anything else (bytes, float, None, non-numeric string) fails the isinstance(value, int) check and raises ValueError('Input must be an integer.').","triggerScenarios":"Setting an integer-parsed resource hint to a float (e.g. 2.5), a bytes value, None, or a non-numeric string like 'many'.","commonSituations":"Config files where numbers were read as floats or strings; env-var injection yielding strings with whitespace/units ('4 GB'); None defaults when an option is missing.","solutions":["Pass a plain int, or an int-parseable decimal string: '4' not 4.0 or b'4'.","Strip units/whitespace and cast explicitly: `int(float(raw))` for floats, `int(raw.strip())` for numeric strings.","Add a validation step in option loading that coerces numeric-looking strings to int before constructing hints."],"exampleFix":"# before\nhints = {'min_ram_number': 4.0}\n# after\nhints = {'min_ram_number': int(4.0)}","handlingStrategy":"type-guard","validationCode":"if isinstance(v, float):\n  v = int(v)\nelif isinstance(v, str):\n  v = int(v.strip())","typeGuard":"def as_int_or_none(v):\n  try:\n    return int(v) if not isinstance(v, int) else v\n  except (TypeError, ValueError):\n    return None","tryCatchPattern":"try:\n  parsed = ResourceHint._parse_int(value)\nexcept ValueError as e:\n  log.error('Bad int hint %r: %s', value, e)\n  raise","preventionTips":["Store integer options as ints, never floats, in configs.","Strip units and whitespace from env/config strings before int().","Reject None defaults for required numeric hints at load time."],"tags":["python","apache-beam","resource-hints","validation"],"backgroundTag":"config-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"}