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

Abierto Apto para principiantes
#41,346 4 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 2 días

@shikhabhadoria ya está trabajando en esto.

Desde el 26/11/2026.

  • #41698 de @shikhabhadoria — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
databases

Línea de trabajo

Empieza en sdks/python/apache_beam/transforms/enrichment_handlers/bigtable.py, en BigTableEnrichmentHandler.__call__ alrededor de las líneas 118-148, y reproduce ambos casos con el beam.Row(user_id=None) del issue y el mock de columna faltante. Rastrea cómo request_dict[self._row_key] llega a str(...)/.encode(...) y dónde la rama de KeyError formatea su mensaje. Se considera terminado cuando una clave None ya no llama a read_row(b'None') y el error de columna faltante nombra self._row_key; ejecuta o amplía las pruebas de enrichment-handler en sdks/python/apache_beam/transforms/enrichment_handlers/.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Java
Estrellas
8.7k
Forks
4.8k
Merge medio
3 d 14 h
PR fusionados (30 d)
428

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/beam

Todos los issues de apache/beam

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.