{"record":{"id":"3b87d5b7192f4126","repo":"apache/beam","slug":"unknown-algorithm-s-supported-algorithms-are-builtin-or-lcg","errorCode":null,"errorMessage":"Unknown algorithm %s. Supported algorithms are \"builtin\" or \"lcg\".","messagePattern":"Unknown algorithm (.+?)\\. Supported algorithms are \"builtin\" or \"lcg\"\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/synthetic_pipeline.py","lineNumber":92,"sourceCode":"  \"\"\"A subclass of `random.Random` from the Python Standard Library that\n  provides a method returning random bytes of arbitrary length.\n  \"\"\"\n\n  # `numpy.random.RandomState` does not provide `random()` method, we keep this\n  # for compatibility reasons.\n  random_sample = Random.random\n\n\ndef get_generator(seed: Optional[int] = None, algorithm: Optional[str] = None):\n  if algorithm is None or algorithm == 'builtin':\n    return _Random(seed)\n  elif algorithm == 'lcg':\n    generator = LCGenerator()\n    if seed is not None:\n      generator.seed(seed)\n    return generator\n  else:\n    raise ValueError(\n        'Unknown algorithm %s. Supported algorithms are \"builtin\" or \"lcg\".',\n        algorithm)\n\n\ndef parse_byte_size(s):\n  suffixes = 'BKMGTP'\n  if s[-1] in suffixes:\n    return int(float(s[:-1]) * 1024**suffixes.index(s[-1]))\n\n  return int(s)\n\n\ndef div_round_up(a, b):\n  \"\"\"Return ceil(a/b).\"\"\"\n  return int(math.ceil(float(a) / b))\n\n\ndef rotate_key(element):","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/synthetic_pipeline.py#L74-L110","documentation":"get_generator selects a synthetic record generator by algorithm name; only 'builtin' and 'lcg' are supported. Any other value raises ValueError. Note the message uses %-style args in raise (an upstream quirk — the args are attached to the exception rather than interpolated in some versions).","triggerScenarios":"Calling get_generator (directly or via _gen_kv_pair/read/process) with algorithm='random', an empty string, or a mis-parsed pipeline option value.","commonSituations":"Typo in the --synthetic-algorithm-like option; config JSON with an algorithm field outside the supported set; copy-pasting an algorithm name from a different tool.","solutions":["Use algorithm='builtin' or algorithm='lcg'","Fix the option/config value feeding the algorithm parameter","Check casing — the comparison is exact lowercase"],"exampleFix":"// before\nget_generator('lcg ', ...)  # trailing space\n// after\nget_generator('lcg', ...)","handlingStrategy":"validation","validationCode":"SUPPORTED = {'builtin', 'lcg'}\nif algorithm not in SUPPORTED:\n    raise ValueError(f'algorithm must be one of {SUPPORTED}')","typeGuard":"def is_supported_algorithm(a):\n    return a in ('builtin', 'lcg')","tryCatchPattern":"try:\n    gen = get_generator(algorithm, byte_size, seed)\nexcept ValueError as e:\n    _LOGGER.error('%s; defaulting to builtin', e)\n    gen = get_generator('builtin', byte_size, seed)","preventionTips":["Whitelist algorithm values in config loading","Lowercase/strip option values before passing them","Document the supported values where options are declared"],"tags":["invalid-enum","synthetic-pipeline","python"],"backgroundTag":"invalid-enum-value","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"}