Cryptic TypeError in proto-plus during assignment with invalid type

Aberta
#17,684 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Pouca atividade
Stack de tecnologia
python

Direção de pesquisa

Comece em proto/message.py, em setattr, ao redor da chamada MergeFrom relatada, e depois rastreie os caminhos de inicialização e MergeFrom mencionados na issue. Reproduza a atribuição de exemplo com batch.pyspark_batch.args = [1000] e verifique se o TypeError resultante identifica a mensagem PysparkBatch, o campo args e o valor inválido.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
5.4k
Forks
1.8k
Merge médio
2d 7h
PRs com merge (30d)
173

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de googleapis/google-cloud-python

Todas as issues de googleapis/google-cloud-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.