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

Đang mở Phù hợp với người mới
#41,346 4 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@shikhabhadoria đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #41698 của @shikhabhadoria — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu trong sdks/python/apache_beam/transforms/enrichment_handlers/bigtable.py, trong BigTableEnrichmentHandler.__call__ quanh dòng 118-148, và tái hiện cả hai trường hợp với beam.Row(user_id=None) của issue và mock cột bị thiếu. Truy vết cách request_dict[self._row_key] đi đến str(...)/.encode(...) và nơi nhánh KeyError định dạng thông điệp của nó. Được coi là hoàn tất khi một khóa None không còn gọi read_row(b'None') và lỗi cột bị thiếu nêu tên self._row_key; chạy hoặc mở rộng các bài kiểm thử enrichment-handler trong sdks/python/apache_beam/transforms/enrichment_handlers/.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Java
Star
8.7k
Fork
4.8k
Merge trung bình
3 ngày 14 giờ
Pull request đã merge (30 ngày)
428

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/beam

Tất cả issue của apache/beam

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.