Cryptic TypeError in proto-plus during assignment with invalid type

Abierto
#17,684 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
python

Línea de trabajo

Empieza en proto/message.py, en setattr, alrededor de la llamada a MergeFrom indicada, y luego sigue las rutas de inicialización y MergeFrom mencionadas en el issue. Reproduce la asignación de ejemplo con batch.pyspark_batch.args = [1000] y verifica que el TypeError resultante identifique el mensaje PysparkBatch, el campo args y el valor no válido.

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

Descripción

priority: p3 type: docs
Determine this is the right repository
  • I determined this is the correct repository in which to report this bug.
Summary of the issue

Context:
When setting a field on a protobuf message using proto-plus with an invalid type or structure, the underlying protocol buffer library fails during initialization or merging.

Expected Behavior:
proto-plus should catch the TypeError and re-raise it with a more descriptive message that includes the specific message class and field name, aiding in debugging type mismatches.

Actual Behavior:
The library raises a cryptic TypeError: bad argument type for built-in operation without any context about which field or message class caused the failure.

API client name and version

proto-plus

Reproduction steps: code

from google.cloud import dataproc_v1

def sample_create_batch():
batch = dataproc_v1.Batch()

# Provide a type that is not a string in the args list. args expects a MutableSequence[str]
batch.pyspark_batch.args = [1000]

sample_create_batch()

Reproduction steps: supporting files

file: mydata.csv

alpha,1,3
beta,2,5
Reproduction steps: actual results

Traceback (most recent call last):
File "test.py", line 42, in
sample_create_batch()
File "test.py", line 24, in sample_create_batch
batch.pyspark_batch.args = [1000 ]
File "/env/lib/python3.11/site-packages/proto/message.py", line 944, in setattr
self._pb.MergeFrom(self._meta.pb(**{key: pb_value}))
TypeError: bad argument type for built-in operation

Reproduction steps: expected results

TypeError: Failed to set field 'args' on PysparkBatch with value [1000]. Underlying error: bad argument type for built-in operation.

OS & version + platform

Linux (Google Cloud Shell) / macOS

Python environment

Python 3.12

Python dependencies

No response

Additional context

The cryptic error is thrown directly from the underlying protocol buffers MergeFrom execution inside proto/message.py. Wrapping the initialization and MergeFrom calls in try-except blocks to provide contextual wrapper errors would greatly improve the developer experience.

Lenguaje dominante
Python
Estrellas
5.4k
Forks
1.8k
Merge medio
2 d 7 h
PR fusionados (30 d)
173

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 googleapis/google-cloud-python

Todos los issues de googleapis/google-cloud-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.