apache/beam · error · ValueError

Input must be an integer.

Error message

Input must be an integer.

What it means

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.').

Solutions

  1. Pass a plain int, or an int-parseable decimal string: '4' not 4.0 or b'4'.
  2. Strip units/whitespace and cast explicitly: `int(float(raw))` for floats, `int(raw.strip())` for numeric strings.
  3. Add a validation step in option loading that coerces numeric-looking strings to int before constructing hints.

Example fix

# before
hints = {'min_ram_number': 4.0}
# after
hints = {'min_ram_number': int(4.0)}
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(v, float):
  v = int(v)
elif isinstance(v, str):
  v = int(v.strip())

Type guard

def as_int_or_none(v):
  try:
    return int(v) if not isinstance(v, int) else v
  except (TypeError, ValueError):
    return None

Try / catch

try:
  parsed = ResourceHint._parse_int(value)
except ValueError as e:
  log.error('Bad int hint %r: %s', value, e)
  raise

Prevention

When it happens

Trigger: Setting an integer-parsed resource hint to a float (e.g. 2.5), a bytes value, None, or a non-numeric string like 'many'.

Common situations: 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.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/1960695205569541. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/transforms/resources.py:105

  @staticmethod
  def register_resource_hint(hint_name: str, hint_class: type) -> None:
    assert issubclass(hint_class, ResourceHint)
    assert hint_class.urn is not None
    ResourceHint._name_to_known_hints[hint_name] = hint_class
    ResourceHint._urn_to_known_hints[hint_class.urn] = hint_class

  @staticmethod
  def _parse_str(value):
    if not isinstance(value, str):
      raise ValueError("Input must be a string.")
    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,

View on GitHub (pinned to 12126d8942)