apache/beam · error · ValueError

need request coder to be able to use Cache with RequestRespo

Error message

need request coder to be able to use Cache with RequestResponseIO.

What it means

ensure_coders_exist() validates that a request coder was supplied when caching is enabled for RequestResponseIO. Caching must encode the request to build cache keys, so a missing request coder makes caching impossible and raises ValueError.

Source

Thrown at sdks/python/apache_beam/io/requestresponse.py:655

        host,
        port,
        time_to_live,
        request_coder=self.request_coder,
        response_coder=self.response_coder,
        kwargs=kwargs,
        source_caller=source_caller,
        mode=_RedisMode.WRITE)

  def expand(
      self, elements: beam.PCollection[tuple[RequestT, ResponseT]]
  ) -> beam.PCollection[ResponseT]:
    return elements | RequestResponseIO(self.redis_caller)


def ensure_coders_exist(request_coder):
  """checks if the coder exists to encode the request for caching."""
  if not request_coder:
    raise ValueError(
        'need request coder to be able to use '
        'Cache with RequestResponseIO.')


class RedisCache(Cache):
  """Configure cache using Redis for
  :class:`apache_beam.io.requestresponse.RequestResponseIO`."""
  def __init__(
      self,
      host: str,
      port: int,
      time_to_live: Union[int, timedelta] = DEFAULT_CACHE_ENTRY_TTL_SEC,
      *,
      request_coder: Optional[coders.Coder] = None,
      response_coder: Optional[coders.Coder] = None,
      **kwargs,
  ):
    """

View on GitHub (pinned to 12126d8942)

Solutions

  1. Pass a proper request coder (e.g. from your request type) when constructing the Cache/RedisCache used with RequestResponseIO.
  2. Ensure the caller-side coders are wired: RequestResponseIO(caller, request_coder=..., response_coder=...) and pass them to the cache.
  3. If caching is not needed, omit the Cache configuration entirely instead of passing a cache without coders.

Example fix

// before
RedisCache(Redis(host='localhost'), 'prefix')  # no request coder
// after
RedisCache(Redis(host='localhost'), 'prefix', request_coder=MyRequestCoder())
Defensive patterns

Strategy: validation

Validate before calling

if cache is not None and request_coder is None:
  raise ValueError('request coder required when caching is enabled')

Type guard

def cache_is_configurable(cache, request_coder) -> bool:
  return cache is None or request_coder is not None

Try / catch

try:
  cache.get_read()
except ValueError as e:
  logging.error('cache misconfiguration: %s', e)

Prevention

When it happens

Trigger: Building a Cache (e.g. RedisCache) and calling get_read()/get_write() when request_coder is None/absent — i.e. RequestResponseIO or the cache was constructed without passing a request coder.

Common situations: Forgetting to pass request_coder/response_coder when configuring RedisCache; copy-pasting cache setup examples without coders; enabling Cache on a pipeline that previously ran without caching.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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