[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyError

未关闭 适合新手
#41,346 4 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@shikhabhadoria 已经在做这个了。

开始于 2026年11月26日。

  • #41698 来自 @shikhabhadoria —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
databases

调研方向

从 sdks/python/apache_beam/transforms/enrichment_handlers/bigtable.py 开始,在 BigTableEnrichmentHandler.__call__ 中大约第 118-148 行处,用 issue 中的 beam.Row(user_id=None) 和缺失列的 mock 复现这两种情况。追踪 request_dict[self._row_key] 如何到达 str(...)/.encode(...),以及 KeyError 分支在哪里格式化其消息。完成标准是:None 键不再调用 read_row(b'None'),并且缺失列错误会指出 self._row_key;运行或扩展 sdks/python/apache_beam/transforms/enrichment_handlers/ 下的 enrichment-handler 测试。

由索引模型根据 Issue 内容生成。

描述

io P2 python
What happened?

BigTableEnrichmentHandler.__call__ (sdks/python/apache_beam/transforms/enrichment_handlers/bigtable.py, lines 118-148) has two bugs when extracting row_key:

  1. Nullable None join keys are queried as literal b'None' (lines 123-126):
    request_dict = request._asdict()
    row_key_str = str(request_dict[self._row_key])
    row_key = row_key_str.encode(self._encoding)
    row = self._table.read_row(row_key, filter_=self._row_filter)
    
    When an input beam.Row has None for self._row_key, str(None) silently coerces it to 'None', issuing a live Bigtable read_row(b'None') RPC (and joining unrelated data if a 'None' row exists).
  2. Blank field name in KeyError message when row_key column is missing (lines 118, 124, 146-147):
    row_key_str is initialized to "" on line 118. When self._row_key is absent from request_dict, request_dict[self._row_key] on line 124 raises KeyError before row_key_str is assigned, so lines 146-147 raise:
    KeyError: 'row_key not found in input PCollection.' (printing an empty string instead of self._row_key).

Minimal reproducer:

from unittest import mock
import apache_beam as beam
from apache_beam.transforms.enrichment_handlers.bigtable import BigTableEnrichmentHandler

h = BigTableEnrichmentHandler(
    project_id='p', instance_id='i', table_id='t', row_key='user_id')
h._table = mock.MagicMock()
h._table.read_row.return_value = None

h(beam.Row(user_id=None))
print('Queried Bigtable key:', h._table.read_row.call_args[0][0])  # b'None'

try:
  h(beam.Row(other_col='x'))
except KeyError as e:
  print('KeyError:', e)  # "KeyError: 'row_key  not found in input PCollection.'"
Cause

request_dict[self._row_key] is passed unconditionally to str(...) without checking is None, and except KeyError: interpolates row_key_str ("") instead of self._row_key.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components
  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • Component: Beam ML
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Infrastructure
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Prism Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner
主要语言
Java
星标
8.7k
派生
4.8k
平均合并
3 天 14 小时
30 天内合并 PR
428

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/beam 的其他 Issue

查看 apache/beam 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。