{"record":{"id":"59a97807ee319c3a","repo":"apache/beam","slug":"input-must-be-a-string","errorCode":null,"errorMessage":"Input must be a string.","messagePattern":"Input must be a string\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/resources.py","lineNumber":97,"sourceCode":"  @staticmethod\n  def get_by_name(name):\n    return ResourceHint._name_to_known_hints[name]\n\n  @staticmethod\n  def is_registered(name):\n    return name in ResourceHint._name_to_known_hints\n\n  @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):","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/resources.py#L79-L115","documentation":"ResourceHint._parse_str is the shared parser for string-valued resource hints (e.g. min_ram or accelerator hints); the value being parsed is not a str, so it cannot be interpreted as a hint value from pipeline options.","triggerScenarios":"Declaring a resource hint whose parser is _parse_str with a non-string value, e.g. `@ResourceHint(urn=..., parser=ResourceHint._parse_str)` used with a hint value given as an int, bytes, or None in the pipeline options.","commonSituations":"Passing numeric hint values (e.g. minimum_ram_number as int when a string parser is expected), YAML/JSON config loading that produces non-str types, typos in option names routing values to the wrong parser.","solutions":["Convert the value to str before setting it: `options.view_as(...).hint_name = str(value)`.","Use the correct parser for the value type (e.g. `_parse_int` for numbers, `_parse_storage_size_str` for sizes like '2GiB').","If your hint values come from config files, coerce loaded values with `str()` or JSON-schema validation at load time."],"exampleFix":"# before\nhints = {'accelerator': 4}\n# after\nhints = {'accelerator': str(4)}","handlingStrategy":"type-guard","validationCode":"if not isinstance(v, str):\n  raise TypeError('hint value must be str')","typeGuard":"def is_str(v):\n  return isinstance(v, str)","tryCatchPattern":"try:\n  parsed = ResourceHint._parse_str(value)\nexcept ValueError as e:\n  log.error('Bad hint value %r: %s', value, e)\n  parsed = ResourceHint._parse_str(str(value))","preventionTips":["Coerce config-file values with str() when feeding string-parsed hints.","Match parser to value type when defining custom ResourceHints.","Validate pipeline option types at startup."],"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"}