{"record":{"id":"4fd9fb8d26f9ad3a","repo":"apache/beam","slug":"flatmaptuple-can-be-used-only-with-callable-objects-received","errorCode":null,"errorMessage":"FlatMapTuple can be used only with callable objects. Received %r instead.","messagePattern":"FlatMapTuple can be used only with callable objects\\. Received %r instead\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":2273,"sourceCode":"  (e.g. key-value pairs).\n\n  Args:\n    fn (callable): a callable object.\n    *args: positional arguments passed to the transform callable.\n    **kwargs: keyword arguments passed to the transform callable.\n\n  Returns:\n    ~apache_beam.pvalue.PCollection:\n    A :class:`~apache_beam.pvalue.PCollection` containing the\n    :func:`FlatMapTuple` outputs.\n\n  Raises:\n    TypeError: If the **fn** passed as argument is not a callable.\n      Typical error is to pass a :class:`DoFn` instance which is supported only\n      for :class:`ParDo`.\n  \"\"\"\n  if not callable(fn):\n    raise TypeError(\n        'FlatMapTuple can be used only with callable objects. '\n        'Received %r instead.' % (fn))\n\n  label = 'FlatMapTuple(%s)' % ptransform.label_from_callable(fn)\n\n  arg_names, defaults = get_function_args_defaults(fn)\n  num_defaults = len(defaults)\n  if num_defaults < len(args) + len(kwargs):\n    raise TypeError('Side inputs must have defaults for FlatMapTuple.')\n\n  if defaults or args or kwargs:\n    wrapper = lambda x, *args, **kwargs: fn(*(tuple(x) + args), **kwargs)\n  else:\n    wrapper = lambda x: fn(*tuple(x))\n\n  # Proxy the type-hint information from the original function to this new\n  # wrapped function.\n  type_hints = get_type_hints(fn).with_defaults(","sourceCodeStart":2255,"sourceCodeEnd":2291,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L2255-L2291","documentation":"beam.FlatMapTuple unpacks tuple elements into fn's parameters and expects fn to return an iterable. Like Map/MapTuple, fn must be a plain callable; passing a DoFn instance or any non-callable raises this TypeError.","triggerScenarios":"beam.FlatMapTuple(SomeDoFn()) or beam.FlatMapTuple(non_callable_object).","commonSituations":"Refactoring FlatMap to FlatMapTuple while keeping a DoFn; passing a class instance without __call__; mixing up ParDo and FlatMapTuple when handling KV/grouped PCollections.","solutions":["Use beam.ParDo for DoFn instances.","Pass a plain callable (lambda, function, method, callable instance) to FlatMapTuple.","Don't invoke the function when passing it: beam.FlatMapTuple(my_fn).","Rewrite the DoFn's process body as a generator function and use that with FlatMapTuple."],"exampleFix":"// before\nbeam.FlatMapTuple(MyDoFn())\n// after\nbeam.FlatMapTuple(lambda k, v: [v] * k)\n// or\nbeam.ParDo(MyDoFn())","handlingStrategy":"type-guard","validationCode":"if not callable(fn):\n    raise TypeError('FlatMapTuple needs a callable, got %r' % (fn,))","typeGuard":"def is_flatmaptuple_fn(fn):\n    return callable(fn) and not isinstance(fn, DoFn)","tryCatchPattern":"try:\n    out = pcoll | beam.FlatMapTuple(fn)\nexcept TypeError as e:\n    if 'callable objects' in str(e):\n        out = pcoll | beam.ParDo(fn)\n    else:\n        raise","preventionTips":["FlatMapTuple fns must return iterables AND be plain callables.","Don't pass DoFn instances outside ParDo.","Keep generator functions around for FlatMapTuple use."],"tags":["python","apache-beam","flatmaptuple","callable"],"backgroundTag":"invalid-argument-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"}