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

オープン 初心者向け
#41,346 コメント 4 件 リアクション 0 件 担当者 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) と missing-column の mock で両方のケースを再現してください。request_dict[self._row_key] が str(...)/.encode(...) にどのように到達するか、また KeyError ブランチがどこでメッセージを整形するかを追跡してください。完了条件は、None キーが read_row(b'None') を呼び出さなくなり、missing-column エラーが 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時間
マージ済み PR(30日)
428

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/beam のほかの issue

apache/beam の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。