googleapis / googleapis/google-cloud-python

Cryptic TypeError in proto-plus during assignment with invalid type

オープン
#17,684 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
priority: p3 type: docs
主要言語
Python
スター
5.4k
フォーク
1.8k
平均マージ
3日 4時間
マージ済み PR(30日)
122

説明

### Determine this is the right repository

- [x] 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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start in proto/message.py at __setattr__ around the reported MergeFrom call, then trace the initialization and MergeFrom paths mentioned in the issue. Reproduce the sample assignment with batch.pyspark_batch.args = [1000] and verify that the resulting TypeError identifies the PysparkBatch message, the args field, and the invalid value.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend-api-design
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
72/100

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

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