Nested message with repeated field not in to_json when mutated after initialization
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
首先,针对 betterproto 2.0.0b6 运行 issue 中嵌套消息的复现,并检查 include_default_values=False 的 to_dict 路径。当已修改的嵌套 repeated 字段出现在返回的 dict 中,同时未更改的默认字段仍被省略时,即可视为完成;如果确定了 repository 中测试的位置,则为这两种情况添加回归覆盖。
由索引模型根据 Issue 内容生成。
描述
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
- 派生
- 236
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielgtaylor/python-betterproto 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 15/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 42/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 45/100
-
bug investigation needed
难度 4/5 3-5 天 新手友好度 38/100
danielgtaylor/python-betterproto#676 · 3 条评论 ·
查看 danielgtaylor/python-betterproto 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
ClockGU/clockwork-backend#169 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/sample-per-model-bedrock#616 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
chnm/teachinghistory-hugo#47 ·
-
good first issue
难度 2/5 1-3 小时 新手友好度 67/100
pandas-dev/pandas-stubs#2047 · 2 条评论 ·
维护者通常 1 天内回复