{"record":{"id":"2d6c6ff44b4969d1","repo":"apache/beam","slug":"invalid-displaydataitem-s-value-must-not-be-none","errorCode":null,"errorMessage":"Invalid DisplayDataItem %s. Value must not be None","messagePattern":"Invalid DisplayDataItem (.+?)\\. Value must not be None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/display.py","lineNumber":344,"sourceCode":"  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    }\n    # TODO: Python Class types should not be special-cased once\n    # the Fn API is in.\n    if self.url is not None:\n      res['url'] = self.url\n    if self.shortValue is not None:\n      res['shortValue'] = self.shortValue","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/display.py#L326-L362","documentation":"DisplayDataItem.is_valid found self.value is None: display data items must carry an actual value (plus key, namespace, and type) to render in the Dataflow UI; this guard fires when an item was built without calling with_value or when the value expression evaluated to None.","triggerScenarios":"display_data() returns an item whose value resolves to None (e.g. an unset attribute used directly as the value) and the DisplayData is later validated via get_dict()/is_valid().","commonSituations":"Returning an uninitialized instance attribute from display_data(); optional config values that end up None; constructing DisplayDataItem with value=None explicitly.","solutions":["Provide a concrete value: use a default (e.g. self.n or 0) instead of a possibly-None attribute.","Omit the item entirely when the value is None (build the dict conditionally).","Convert None to a sentinel string if the presence of the key matters."],"exampleFix":"// before\ndef display_data(self):\n    return {'threshold': self.threshold}  # may be None\n// after\ndef display_data(self):\n    dd = {}\n    if self.threshold is not None:\n        dd['threshold'] = self.threshold\n    return dd","handlingStrategy":"validation","validationCode":"for item in display_data.items:\n    if getattr(item, 'value', None) is None:\n        raise ValueError('display data item missing value')","typeGuard":"def item_has_value(item) -> bool:\n    return getattr(item, 'value', None) is not None","tryCatchPattern":"try:\n    d = display_data.get_dict()\nexcept ValueError as e:\n    if 'Value must not be None' in str(e):\n        drop_none_valued_items(display_data)\n        d = display_data.get_dict()\n    else:\n        raise","preventionTips":["Never return None-valued attributes from display_data()","Build display data dicts conditionally","Give config attributes sane non-None defaults"],"tags":["apache-beam","python","display-data","validation"],"backgroundTag":"null-argument","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"}