apache/beam · error · ValueError
Input must be a string or integer.
Error message
Input must be a string or integer.
What it means
`_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.').
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.
Example fix
# before
hints = {'min_ram_bytes': 2.5}
# after
hints = {'min_ram_bytes': '2GiB'} Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(v, (str, int)):
raise TypeError('size hint must be str like "2GiB" or int bytes') Type guard
def is_size_value(v): return isinstance(v, (str, int)) and not isinstance(v, bool)
Try / catch
try:
parsed = ResourceHint._parse_storage_size_str(value)
except ValueError as e:
log.error('Bad size hint %r: %s', value, e)
raise Prevention
- 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.
When it happens
Trigger: 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'.
Common situations: YAML/JSON configs producing floats or non-scalars; programmatic construction passing numbers-with-units objects or None when the option was absent.
Related errors
- Input must be a string.
- Input must be an integer.
- An unsupported sink was specified
- At least one of --render_port or --render_output must be…
- buffer_sec must be >= 0, got
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/c816b7382373ccdd.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/transforms/resources.py:116
return value.encode('ascii')
@staticmethod
def _parse_int(value):
if isinstance(value, str):
value = int(value)
if not isinstance(value, int):
raise ValueError("Input must be an integer.")
return str(value).encode('ascii')
@staticmethod
def _parse_storage_size_str(value):
"""Parses a human-friendly storage size string into a number of bytes.
"""
if isinstance(value, int):
return ResourceHint._parse_int(value)
if not isinstance(value, str):
raise ValueError("Input must be a string or integer.")
value = value.strip().replace(" ", "")
units = {
'PiB': 2**50,
'TiB': 2**40,
'GiB': 2**30,
'MiB': 2**20,
'KiB': 2**10,
'PB': 10**15,
'TB': 10**12,
'GB': 10**9,
'MB': 10**6,
'KB': 10**3,
'B': 1,
}
match = re.match(r'.*?(\D+)$', value)
if not match:
raise ValueError("Unrecognized value pattern.")View on GitHub (pinned to 12126d8942)