{"record":{"id":"e9aa1a43ec555d4a","repo":"apache/beam","slug":"invalid-displaydataitem-s-key-must-not-be-none","errorCode":null,"errorMessage":"Invalid DisplayDataItem %s. Key must not be None.","messagePattern":"Invalid DisplayDataItem (.+?)\\. Key must not be None\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/display.py","lineNumber":338,"sourceCode":"    if self._drop_if_none and self.value is None:\n      return True\n    if self._drop_if_default and self.value == self._default:\n      return True\n    return False\n\n  def is_valid(self):\n    # type: () -> None\n\n    \"\"\" Checks that all the necessary fields of the :class:`DisplayDataItem`\n    are filled in. It checks that neither key, namespace, value or type are\n    :data:`None`.\n\n    Raises:\n      ValueError: If the item does not have a key, namespace,\n        value or type.\n    \"\"\"\n    if self.key is None:\n      raise ValueError(\n          'Invalid DisplayDataItem %s. Key must not be None.' % self)\n    if self.namespace is None:\n      raise ValueError(\n          'Invalid DisplayDataItem %s. Namespace must not be None' % self)\n    if self.value is None:\n      raise ValueError(\n          'Invalid DisplayDataItem %s. Value must not be None' % self)\n    if self.type is None:\n      raise ValueError(\n          'Invalid DisplayDataItem. Value {} is of an unsupported type.'.format(\n              self.value))\n\n  def _get_dict(self):\n    res = {\n        'key': self.key,\n        'namespace': self.namespace,\n        'type': self.type if self.type != 'CLASS' else 'STRING'\n    }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/display.py#L320-L356","documentation":"DisplayDataItem.is_valid validates that an item carries a key; it raises ValueError when the item's key attribute is None. Every display data item must have a key to be labeled in the runner API proto.","triggerScenarios":"Building/serializing a DisplayDataItem where the key was never set (e.g. DisplayData created from items dict where key metadata is missing) and get_dict()/is_valid() is invoked.","commonSituations":"Manually constructing DisplayDataItem without a key; programmatic DisplayData manipulation dropping the key field; buggy custom display_data implementations.","solutions":["Set a key when creating the item: DisplayData.create_from or provide a non-None key field.","Inspect the offending item (printed in the message) to find where the key was lost.","Avoid manual DisplayDataItem construction; derive items from display_data() dictionaries."],"exampleFix":"// before\nitem = DisplayDataItem(value=42)  # no key\n// after\nitem = DisplayDataItem(key='my_value', value=42)","handlingStrategy":"validation","validationCode":"for item in display_data.items:\n    if getattr(item, 'key', None) is None:\n        raise ValueError('display data item missing key')","typeGuard":"def item_has_key(item) -> bool:\n    return getattr(item, 'key', None) is not None","tryCatchPattern":"try:\n    d = display_data.get_dict()\nexcept ValueError as e:\n    if 'Key must not be None' in str(e):\n        skip_or_fix_invalid_items(display_data)\n        d = display_data.get_dict()\n    else:\n        raise","preventionTips":["Create items via DisplayData.create_from, not manually","Keep keys defined in display_data() dicts","Validate items before serializing pipelines"],"tags":["apache-beam","python","display-data","validation"],"backgroundTag":"empty-required-field","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"}