{"record":{"id":"8fef4ed368609ecc","repo":"apache/beam","slug":"either-fields-or-condition-value-fn-must-be-specified","errorCode":null,"errorMessage":"Either fields or condition_value_fn must be specified","messagePattern":"Either fields or condition_value_fn must be specified","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/enrichment_handlers/bigquery.py","lineNumber":195,"sourceCode":"      if self._batching_kwargs:\n        return row_list\n      else:\n        return row_list[0]\n    except BadRequest as e:\n      raise BadRequest(\n          f'Could not execute the query: {query}. Please check if '\n          f'the query is properly formatted and the BigQuery '\n          f'table exists. {e}')\n    except RuntimeError as e:\n      raise RuntimeError(f\"Could not complete the query request: {query}. {e}\")\n\n  def create_row_key(self, row: beam.Row):\n    if self.condition_value_fn:\n      return tuple(self.condition_value_fn(row))\n    if self.fields:\n      row_dict = row._asdict()\n      return (tuple(row_dict[field] for field in self.fields))\n    raise ValueError(\"Either fields or condition_value_fn must be specified\")\n\n  def __call__(self, request: Union[beam.Row, list[beam.Row]], *args, **kwargs):\n    if isinstance(request, list):\n      values = []\n      responses = []\n      requests_map: dict[Any, list[beam.Row]] = defaultdict(list)\n      batch_size = len(request)\n      raw_query = self.query_template\n      if batch_size > 1:\n        batched_condition_template = ' or '.join(\n            [fr'({self.row_restriction_template})'] * batch_size)\n        raw_query = self.query_template.replace(\n            self.row_restriction_template, batched_condition_template)\n      for req in request:\n        request_dict = req._asdict()\n        try:\n          current_values = (\n              self.condition_value_fn(req) if self.condition_value_fn else","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/enrichment_handlers/bigquery.py#L177-L213","documentation":"BigQuerySanitized enrichment handler's create_row_key found neither a condition_value_fn nor a fields list on the handler config; with no way to derive the join key from the input row, row-key generation (and hence caching/enrichment) cannot proceed.","triggerScenarios":"Calling __call__/create_row_key on a BigQueryEnrichmentHandler constructed without condition_value_fn and without fields (possible when configured via query_fn and bypassing validation, or when using BatchingKey = fields-based path with neither set).","commonSituations":"Handler built with only query_fn but used in a code path (batching key creation) that requires fields/condition_value_fn; validation skipped by direct construction.","solutions":["Provide fields (list of key column names) or condition_value_fn on the handler","If using query_fn exclusively, use the non-batched call path or ensure fields are still supplied for key creation"],"exampleFix":"// before\nBigQueryEnrichmentHandler(query_fn=fn)\n// after\nBigQueryEnrichmentHandler(query_fn=fn, fields=['id'])","handlingStrategy":"validation","validationCode":"def ensure_key_source(handler):\n    if not getattr(handler, 'condition_value_fn', None) and not getattr(handler, 'fields', None):\n        raise ValueError('Handler needs fields or condition_value_fn for key creation')","typeGuard":null,"tryCatchPattern":"try:\n    responses = handler(rows)\nexcept ValueError as e:\n    logger.error('Cannot build row key: %s', e)\n    raise","preventionTips":["Always provide fields even when using query_fn if key-based batching is used","Never construct the handler bypassing __init__ validation","Test one enrichment call locally before deploying"],"tags":["apache-beam","bigquery","missing-argument"],"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-20T03:17:13.778Z"}