{"record":{"id":"c26a4508456a8cfb","repo":"apache/beam","slug":"caching-is-not-supported-for-customqueryconfig-consider","errorCode":null,"errorMessage":"Caching is not supported for CustomQueryConfig. Consider using TableFieldsQueryConfig or TableFunctionQueryConfig instead.","messagePattern":"Caching is not supported for CustomQueryConfig\\. Consider using TableFieldsQueryConfig or TableFunctionQueryConfig instead\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql.py","lineNumber":615,"sourceCode":"      List of parameter names found in the template (e.g., [\"id\"])\n    \"\"\"\n    return re.findall(r':(\\w+)', template)\n\n  def create_row_key(self, row: beam.Row):\n    if isinstance(self._query_config, TableFunctionQueryConfig):\n      return tuple(self._query_config.where_clause_value_fn(row))\n    if isinstance(self._query_config, TableFieldsQueryConfig):\n      row_dict = row._asdict()\n      return (\n          tuple(\n              row_dict[where_clause_field]\n              for where_clause_field in self._query_config.where_clause_fields))\n    raise ValueError(\n        \"Either where_clause_fields or where_clause_value_fn must be specified\")\n\n  def get_cache_key(self, request: Union[beam.Row, list[beam.Row]]):\n    if isinstance(self._query_config, CustomQueryConfig):\n      raise NotImplementedError(\n          \"Caching is not supported for CustomQueryConfig. \"\n          \"Consider using TableFieldsQueryConfig or \" +\n          \"TableFunctionQueryConfig instead.\")\n\n    if isinstance(request, list):\n      cache_keys = []\n      for req in request:\n        req_dict = req._asdict()\n        try:\n          if isinstance(self._query_config, TableFunctionQueryConfig):\n            current_values = self._query_config.where_clause_value_fn(req)\n          elif isinstance(self._query_config, TableFieldsQueryConfig):\n            current_values = [\n                req_dict[field]\n                for field in self._query_config.where_clause_fields\n            ]\n          key = ';'.join(map(repr, current_values))\n          cache_keys.append(key)","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql.py#L597-L633","documentation":"get_cache_key derives cache keys from request fields, which only works for table-based configs; for CustomQueryConfig the handler raises NotImplementedError advising TableFieldsQueryConfig or TableFunctionQueryConfig when caching is used.","triggerScenarios":"Constructing CloudSQLEnrichmentHandler with caching enabled (e.g. cache_size > 0) while using CustomQueryConfig; calling get_cache_key directly on a CustomQueryConfig-backed handler.","commonSituations":"Enabling the built-in cache for performance while keeping CustomQueryConfig; copy-pasting a handler setup that had caching on.","solutions":["Switch to TableFieldsQueryConfig or TableFunctionQueryConfig to use caching.","Disable caching (cache_size=0) if you must keep CustomQueryConfig.","Review handler constructor cache parameters before combining with CustomQueryConfig."],"exampleFix":"# before\nhandler = CloudSQLEnrichmentHandler(query_config=CustomQueryConfig(query=...), connection_config=cfg, cache_size=100)\n# after\nhandler = CloudSQLEnrichmentHandler(query_config=TableFieldsQueryConfig(..., where_clause_fields=[\"id\"]), connection_config=cfg, cache_size=100)","handlingStrategy":"validation","validationCode":"if isinstance(query_config, CustomQueryConfig):\n    cache_size = 0  # caching unsupported for CustomQueryConfig","typeGuard":"def cache_compatible(qc) -> bool:\n    return isinstance(qc, (TableFieldsQueryConfig, TableFunctionQueryConfig))","tryCatchPattern":"try:\n    handler = CloudSQLEnrichmentHandler(query_config=qc, connection_config=cc, cache_size=size)\nexcept NotImplementedError as e:\n    log.error(\"Caching unavailable for this config: %s\", e)\n    raise","preventionTips":["Enable caching only with table-based query configs.","Set cache_size=0 when using CustomQueryConfig.","Review handler constructor docs before combining cache options."],"tags":["python","cloudsql","caching","configuration"],"backgroundTag":"method-not-implemented","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"}