Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Nested message with repeated field not in to_json when mutated after initialization

オープン
#543 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

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

調査の方向性

まず、betterproto 2.0.0b6 に対して issue のネストされたメッセージの再現を実行し、include_default_values=False の to_dict パスを調査します。変更されたネストされた repeated フィールドが返された dict に現れ、変更されていないデフォルトフィールドは引き続き省略されていれば完了です。リポジトリ内のテスト場所を特定できた場合は、両方のケースについて回帰テストを追加します。

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

説明

bug investigation needed
Summary

Possibly related to #199

Given a message with a nested message field containing a repeated field, if the field is mutated (eg. via list.append) after initialization, to_dict will not include it.

Reproduction Steps

Given a proto schema like this

syntax = "proto3";

message RootMessage {
  NestedMessage nested = 1;
}

message NestedMessage {
  repeated string content = 1;
}

Running the following script

message = RootMessage()

message.nested.content.append("test-content")

print("Including default values: True")
pprint(message.to_dict(include_default_values=True))

print("Including default values: False")
pprint(message.to_dict(include_default_values=False))

will result in:

Including default values: True
{'nested': {'content': ['test-content']}}

Including default values: False
{}
Expected Results

I would expect the content field of the nested message to appear in the returned dict also when include_default_values is set to False, as its content was mutated and it's no longer the default value.

Actual Results

to_dict returns an empty dict

System Information
libprotoc 3.21.6
Python 3.10.13
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: [email protected]
License: MIT
Location: /home/marco/.local/share/rtx/installs/python/3.10.13/lib/python3.10/site-packages
Requires: grpclib, python-dateutil
Required-by: 
Checklist
  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.
主要言語
Python
スター
1.8k
フォーク
235
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

danielgtaylor/python-betterproto のほかの issue

danielgtaylor/python-betterproto の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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