[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyError
维护者通常 2 天内回复
评估
调研方向
从 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 内容生成。
描述
What happened?
BigTableEnrichmentHandler.__call__ (sdks/python/apache_beam/transforms/enrichment_handlers/bigtable.py, lines 118-148) has two bugs when extracting row_key:
- Nullable
Nonejoin keys are queried as literalb'None'(lines123-126):
When an inputrequest_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)beam.RowhasNoneforself._row_key,str(None)silently coerces it to'None', issuing a live Bigtableread_row(b'None')RPC (and joining unrelated data if a'None'row exists). - Blank field name in
KeyErrormessage whenrow_keycolumn is missing (lines118, 124, 146-147):
row_key_stris initialized to""on line118. Whenself._row_keyis absent fromrequest_dict,request_dict[self._row_key]on line124raisesKeyErrorbeforerow_key_stris assigned, so lines146-147raise:
KeyError: 'row_key not found in input PCollection.'(printing an empty string instead ofself._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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/beam 的其他 Issue
-
awaiting triage java new feature P2
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
Release notes links wrong可能已有人在做 @schizophrenicmaniac 于 20 天前认领。 未关闭bug P3
难度 1/5 1 小时以内 新手友好度 67/100
apache/beam#41197 · 3 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
apache/beam#39624 · 2 个 reaction ·
维护者通常 2 天内回复
-
[Bug]: PubsubIO used in batch incorrect batch cutoff size可能已有人在做 @1fanwang 于 98 天前认领。 未关闭bug io P3 pinned pubsub
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
build P3 sub-task
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 2 天内回复
相似的 Issue
-
bug vault
难度 2/5 1-3 小时 新手友好度 88/100
bancolombia/secrets-manager#150 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 92/100
HexaHexes/neoforge-mod-template#124 ·
维护者通常 1 天内回复
-
source-survicate: pagination reads pagination and stops after one page; substreams drop survey_id未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
OpenLiberty/open-liberty#36410 ·
维护者通常 1 天内回复
-
Downstream doc assembly fails on a tooltip that holds an escaped `]`可能已有人在做 @rolfedh 今天认领。 未关闭triage/needs-triage
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复