{"record":{"id":"0f001c03d3ce2305","repo":"apache/beam","slug":"elements-must-be-a-list-of-elements","errorCode":null,"errorMessage":"'elements must be a list of elements'","messagePattern":"'elements must be a list of elements'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_provider.py","lineNumber":901,"sourceCode":"    will result in an output with two elements with a schema of\n    Row(element=int, a=int) looking like:\n\n        Row(element=1, a=None)\n        Row(element=None, a=2)\n\n    Args:\n        elements: The set of elements that should belong to the PCollection.\n            YAML/JSON-style mappings will be interpreted as Beam rows.\n            Primitives will be mapped to rows with a single \"element\" field.\n        reshuffle: (optional) Whether to introduce a reshuffle (to possibly\n            redistribute the work) if there is more than one element in the\n            collection. Defaults to True.\n    \"\"\"\n    # Though str and dict are technically iterable, we disallow them\n    # as using the characters or keys respectively is almost certainly\n    # not the intent.\n    if not isinstance(elements, Iterable) or isinstance(elements, (dict, str)):\n      raise TypeError('elements must be a list of elements')\n\n    if elements:\n      # Normalize elements to be all dicts or all primitives.\n      has_dict = False\n      has_non_dict = False\n      for e in elements:\n        if isinstance(e, dict):\n          has_dict = True\n        else:\n          has_non_dict = True\n        if has_dict and has_non_dict:\n          break\n\n      if has_dict and has_non_dict:\n        elements = [\n            e if isinstance(e, dict) else {\n                'element': e\n            } for e in elements","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_provider.py#L883-L919","documentation":"The Create/Inline transform (yaml_provider.py:901) accepts 'elements' only as an iterable that is not a dict or str — i.e. a real list/sequence of elements. Passing a dict (keys would silently be used) or a string (characters would be used) raises TypeError 'elements must be a list of elements'.","triggerScenarios":"YAML inline create with elements: '{a: 1, b: 2}' (a mapping) or elements: 'hello' (a string); programmatically calling the transform with a dict or str.","commonSituations":"Wanting to create a single record and passing a dict directly instead of a one-element list; YAML quoting confusion turning an intended list into a string.","solutions":["Wrap the value in a list: elements: [{a: 1}] for a single record.","For multiple records provide a YAML list: elements: [{a: 1}, {a: 2}].","If passing strings as data, wrap each in a list: ['hello'] not 'hello'."],"exampleFix":"# before\n- type: Create\n  elements: {a: 1}\n# after\n- type: Create\n  elements:\n    - a: 1","handlingStrategy":"type-guard","validationCode":"def validate_elements(elements):\n    if not isinstance(elements, list) or isinstance(elements, (dict, str)):\n        raise SystemExit('elements must be a list; wrap single values: [{a: 1}]')","typeGuard":"def is_element_list(x) -> bool:\n    return isinstance(x, list) and not isinstance(x, (dict, str))","tryCatchPattern":"try:\n    result = create_transform(pcoll, elements)\nexcept TypeError as e:\n    log.error('Inline Create elements malformed: %s', e)\n    raise","preventionTips":["Always author elements as a YAML list, even for a single record.","Quote strings that look like maps carefully so YAML does not change their type.","Remember dicts and strings are rejected deliberately — wrap them in a list."],"tags":["python","apache-beam","yaml","create","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"}