{"record":{"id":"c816b7382373ccdd","repo":"apache/beam","slug":"input-must-be-a-string-or-integer","errorCode":null,"errorMessage":"Input must be a string or integer.","messagePattern":"Input must be a string or integer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/resources.py","lineNumber":116,"sourceCode":"    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,\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.\")","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/resources.py#L98-L134","documentation":"`_parse_storage_size_str` accepts an int (delegating to _parse_int) or a human-friendly size string like '2GiB'. Any other type (bytes, float, None, list) raises ValueError('Input must be a string or integer.').","triggerScenarios":"Setting a storage-size resource hint with a float (e.g. 1.5), bytes value, or None instead of an int or a string like '512MiB'.","commonSituations":"YAML/JSON configs producing floats or non-scalars; programmatic construction passing numbers-with-units objects or None when the option was absent.","solutions":["Pass either an int byte count or a string with a supported unit (PiB/TiB/GiB/MiB/KiB/KB/MB/GB).","Convert floats explicitly: `str(int(value))` if the float is a whole number, otherwise round per your policy first.","Validate/normalize the option at load time: reject None and non-scalars before they reach ResourceHint parsing."],"exampleFix":"# before\nhints = {'min_ram_bytes': 2.5}\n# after\nhints = {'min_ram_bytes': '2GiB'}","handlingStrategy":"type-guard","validationCode":"if not isinstance(v, (str, int)):\n  raise TypeError('size hint must be str like \"2GiB\" or int bytes')","typeGuard":"def is_size_value(v):\n  return isinstance(v, (str, int)) and not isinstance(v, bool)","tryCatchPattern":"try:\n  parsed = ResourceHint._parse_storage_size_str(value)\nexcept ValueError as e:\n  log.error('Bad size hint %r: %s', value, e)\n  raise","preventionTips":["Write sizes in config files as strings with units ('512MiB') or ints of bytes.","Ensure YAML/JSON loaders parse size fields as scalars, not floats or objects.","Normalize None/missing values before constructing resource hints."],"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"}