{"record":{"id":"3dc5f453528b5bae","repo":"apache/beam","slug":"need-request-coder-to-be-able-to-use-cache-with","errorCode":null,"errorMessage":"need request coder to be able to use Cache with RequestResponseIO.","messagePattern":"need request coder to be able to use Cache with RequestResponseIO\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/requestresponse.py","lineNumber":655,"sourceCode":"        host,\n        port,\n        time_to_live,\n        request_coder=self.request_coder,\n        response_coder=self.response_coder,\n        kwargs=kwargs,\n        source_caller=source_caller,\n        mode=_RedisMode.WRITE)\n\n  def expand(\n      self, elements: beam.PCollection[tuple[RequestT, ResponseT]]\n  ) -> beam.PCollection[ResponseT]:\n    return elements | RequestResponseIO(self.redis_caller)\n\n\ndef ensure_coders_exist(request_coder):\n  \"\"\"checks if the coder exists to encode the request for caching.\"\"\"\n  if not request_coder:\n    raise ValueError(\n        'need request coder to be able to use '\n        'Cache with RequestResponseIO.')\n\n\nclass RedisCache(Cache):\n  \"\"\"Configure cache using Redis for\n  :class:`apache_beam.io.requestresponse.RequestResponseIO`.\"\"\"\n  def __init__(\n      self,\n      host: str,\n      port: int,\n      time_to_live: Union[int, timedelta] = DEFAULT_CACHE_ENTRY_TTL_SEC,\n      *,\n      request_coder: Optional[coders.Coder] = None,\n      response_coder: Optional[coders.Coder] = None,\n      **kwargs,\n  ):\n    \"\"\"","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/requestresponse.py#L637-L673","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a proper request coder (e.g. from your request type) when constructing the Cache/RedisCache used with RequestResponseIO.","Ensure the caller-side coders are wired: RequestResponseIO(caller, request_coder=..., response_coder=...) and pass them to the cache.","If caching is not needed, omit the Cache configuration entirely instead of passing a cache without coders."],"exampleFix":"// before\nRedisCache(Redis(host='localhost'), 'prefix')  # no request coder\n// after\nRedisCache(Redis(host='localhost'), 'prefix', request_coder=MyRequestCoder())","handlingStrategy":"validation","validationCode":"if cache is not None and request_coder is None:\n  raise ValueError('request coder required when caching is enabled')","typeGuard":"def cache_is_configurable(cache, request_coder) -> bool:\n  return cache is None or request_coder is not None","tryCatchPattern":"try:\n  cache.get_read()\nexcept ValueError as e:\n  logging.error('cache misconfiguration: %s', e)","preventionTips":["Always pass both request and response coders when enabling Cache","Document coder requirements in cache setup helpers","Fall back to no-cache mode when coders are absent"],"tags":["python","apache-beam","cache","coders"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}