{"record":{"id":"bf3a3412dc986416","repo":"apache/beam","slug":"flattenwith-only-takes-other-pcollections-and-ptransforms","errorCode":null,"errorMessage":"FlattenWith only takes other PCollections and PTransforms, got {other}","messagePattern":"FlattenWith only takes other PCollections and PTransforms, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":4176,"sourceCode":"  This is equivalent to creating a tuple containing both the input and the\n  other PCollection(s), but has the advantage that it can be more easily used\n  inline.\n\n  Root PTransforms can be passed as well as PCollections, in which case their\n  outputs will be flattened.\n  \"\"\"\n  def __init__(self, *others):\n    self._others = others\n\n  def expand(self, pcoll):\n    pcolls = [pcoll]\n    for other in self._others:\n      if isinstance(other, pvalue.PCollection):\n        pcolls.append(other)\n      elif isinstance(other, PTransform):\n        pcolls.append(pcoll.pipeline | other)\n      else:\n        raise TypeError(\n            'FlattenWith only takes other PCollections and PTransforms, '\n            f'got {other}')\n    return tuple(pcolls) | Flatten()\n\n\nclass Create(PTransform):\n  \"\"\"A transform that creates a PCollection from an iterable.\"\"\"\n  def __init__(self, values, reshuffle=True):\n    \"\"\"Initializes a Create transform.\n\n    Args:\n      values: An object of values for the PCollection\n    \"\"\"\n    super().__init__()\n    if isinstance(values, (str, bytes)):\n      raise TypeError(\n          'PTransform Create: Refusing to treat string as '\n          'an iterable. (string=%r)' % values)","sourceCodeStart":4158,"sourceCodeEnd":4194,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L4158-L4194","documentation":"Raised by FlattenWith.expand when one of the stored _others is neither a PCollection nor a PTransform. FlattenWith only knows how to append a PCollection directly or apply a PTransform to the source pipeline's input; any other object cannot contribute a collection to the flatten.","triggerScenarios":"pc | beam.FlattenWith(some_raw_list), FlattenWith(42), or accidentally passing a list of PCollections instead of each PCollection individually; passing a PValue that is not a PCollection.","commonSituations":"Collecting things to merge into a plain list and passing the list itself; mixing string/table references (other runners/SQL) with PCollection arguments; typos where a variable holds the wrong object.","solutions":["Pass PCollections directly, unpacking lists: beam.FlattenWith(*other_pcolls).","If merging with a transform's output, pass the PTransform: | beam.FlattenWith(beam.Create([...])).","Ensure each argument is a PCollection (e.g. PValue vs PCollection distinction) or a PTransform.","Unpack any container variables before passing."],"exampleFix":"// before\nmerged = pc | beam.FlattenWith(other_pcolls)  # other_pcolls is a list\n// after\nmerged = pc | beam.FlattenWith(*other_pcolls)","handlingStrategy":"type-guard","validationCode":"assert all(isinstance(o, (PCollection, PTransform)) for o in others), 'FlattenWith accepts only PCollections and PTransforms'","typeGuard":"def is_flatten_with_arg(o):\n    return isinstance(o, (PCollection, PTransform))","tryCatchPattern":"try:\n    merged = pc | beam.FlattenWith(*others)\nexcept TypeError as e:\n    log.error('Bad FlattenWith argument: %s', e)","preventionTips":["Unpack lists with * before passing","Verify each argument is a PCollection or PTransform","Don't pass raw containers or references"],"tags":["python","apache-beam","flatten","type-mismatch"],"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"}