apache/beam · error · ValueError

Element of class . does not subclass HasDisplayData

Error message

Element of class {}.{} does not subclass HasDisplayData

What it means

DisplayData.create_from requires an object that subclasses HasDisplayData (transforms, DoFns, etc.). It raises ValueError when the passed object does not implement that interface, including the object's module and class in the message.

Solutions

  1. Pass an object that subclasses HasDisplayData (e.g. a PTransform or DoFn instance).
  2. For pipeline options, use DisplayData.create_from_options() instead.
  3. Make your custom class inherit HasDisplayData if it defines display_data().

Example fix

// before
dd = DisplayData.create_from(my_plain_fn)
// after
class MyDoFn(beam.DoFn):
    def display_data(self):
        return {'n': self.n}
dd = DisplayData.create_from(MyDoFn(n=3))
Defensive patterns

Strategy: type-guard

Validate before calling

from apache_beam.transforms.display import HasDisplayData
assert isinstance(obj, HasDisplayData), 'create_from needs a HasDisplayData instance'

Type guard

def has_display_data(o) -> bool:
    from apache_beam.transforms.display import HasDisplayData
    return isinstance(o, HasDisplayData)

Try / catch

try:
    dd = DisplayData.create_from(obj)
except ValueError as e:
    if 'does not subclass HasDisplayData' in str(e):
        dd = DisplayData.create_from_options(obj)  # if it is PipelineOptions
    else:
        raise

Prevention

When it happens

Trigger: Calling DisplayData.create_from(obj) where obj is a plain function, dict, PipelineOptions instance, or any non-HasDisplayData object.

Common situations: Passing a lambda/plain function instead of a DoFn; passing PipelineOptions here instead of create_from_options; passing a custom transform that forgot to inherit from PTransform/HasDisplayData.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/9d76783cee304b9a. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/transforms/display.py:243

    }
    return cls(pipeline_options._get_display_data_namespace(), items)

  @classmethod
  def create_from(cls, has_display_data, extra_items=None):
    """ Creates :class:`~apache_beam.transforms.display.DisplayData` from a
    :class:`HasDisplayData` instance.

    Returns:
      ~apache_beam.transforms.display.DisplayData:
        A :class:`~apache_beam.transforms.display.DisplayData` instance with
        populated items.

    Raises:
      ValueError: If the **has_display_data** argument is
        not an instance of :class:`HasDisplayData`.
    """
    if not isinstance(has_display_data, HasDisplayData):
      raise ValueError(
          'Element of class {}.{} does not subclass HasDisplayData'.format(
              has_display_data.__module__, has_display_data.__class__.__name__))
    if extra_items is None:
      extra_items = {}
    return cls(
        has_display_data._get_display_data_namespace(),
        dict(**has_display_data.display_data(), **extra_items))


class DisplayDataItem(object):
  """ A DisplayDataItem represents a unit of static display data.

  Each item is identified by a key and the namespace of the component the
  display item belongs to.
  """
  typeDict = {
      str: 'STRING',
      int: 'INTEGER',

View on GitHub (pinned to 12126d8942)