{"record":{"id":"20325c9066075653","repo":"apache/beam","slug":"maptuple-can-be-used-only-with-callable-objects-received-r","errorCode":null,"errorMessage":"MapTuple can be used only with callable objects. Received %r instead.","messagePattern":"MapTuple 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":2195,"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:`MapTuple` 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        'MapTuple can be used only with callable objects. '\n        'Received %r instead.' % (fn))\n\n  label = 'MapTuple(%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 MapTuple.')\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(*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":2177,"sourceCodeEnd":2213,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L2177-L2213","documentation":"beam.MapTuple unpacks tuple elements into fn's positional parameters, so fn must be a callable accepting multiple positional args. A non-callable (typically a DoFn instance) raises this TypeError before any wrapping occurs.","triggerScenarios":"beam.MapTuple(SomeDoFn()) or beam.MapTuple(non_callable) where fn lacks __call__.","commonSituations":"Confusing MapTuple with ParDo when processing KV/grouped PCollections; refactoring Map to MapTuple and accidentally passing a DoFn; copy-paste between Map/FlatMap/MapTuple call sites.","solutions":["Use beam.ParDo for DoFn instances.","Pass a function-style callable like beam.MapTuple(lambda k, v: ...).","Confirm the object exposes __call__ if you intend a callable class instance.","If the DoFn's process signature unpacks tuples, extract a plain function equivalent for MapTuple usage."],"exampleFix":"// before\nbeam.MapTuple(MyDoFn())\n// after\nbeam.MapTuple(lambda k, v: (k, v * 2))\n// or for DoFn:\nbeam.ParDo(MyDoFn())","handlingStrategy":"type-guard","validationCode":"if not callable(fn):\n    raise TypeError('MapTuple needs a callable, got %r' % (fn,))","typeGuard":"def is_maptuple_fn(fn):\n    return callable(fn) and not isinstance(fn, DoFn)","tryCatchPattern":"try:\n    out = pcoll | beam.MapTuple(fn)\nexcept TypeError as e:\n    if 'callable objects' in str(e):\n        out = pcoll | beam.ParDo(fn)\n    else:\n        raise","preventionTips":["MapTuple fns should take unpacked positional params (k, v, ...).","Keep a lint rule banning DoFn instances in Map/FlatMap family.","Document which transforms accept DoFns on your team's Beam guide."],"tags":["python","apache-beam","maptuple","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"}