Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Empty list cannot be parsed by `repeated`

未关闭
#509 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
grpc, python
领域
api

调研方向

从生成的 init.py 中调用消息解析的部分开始,然后检查 betterproto/init.py 中 FromString 和 parse 附近的代码,使用提供的 GenerateRequest(messages=[]) 示例和 protoc 命令重现该故障。当空的 repeated 字段能够在没有 Pydantic 验证错误的情况下成功解码时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug

Versions

betterproto[compiler]==2.0.0b6
grpcio-tools
pydantic==1.10.8

I get the following error on the server side:

023-07-10 15:48:08,980 - 140154842511168 - server.py-server:468 - ERROR: Application error
Traceback (most recent call last):
  File "/worker-py/.direnv/python-3.10/lib/python3.10/site-packages/grpclib/server.py", line 446, in request_handler
    await method_func(stream)
  File "/worker-py/generated/__init__.py", line 157, in __rpc_teamlead_reply
    request = await stream.recv_message()
  File "/worker-py/.direnv/python-3.10/lib/python3.10/site-packages/grpclib/server.py", line 136, in recv_message
    message = await recv_message(self._stream, self._codec, self._recv_type)
  File "/worker-py/.direnv/python-3.10/lib/python3.10/site-packages/grpclib/stream.py", line 32, in recv_message
    message = codec.decode(message_bin, message_type)
  File "/worker-py/.direnv/python-3.10/lib/python3.10/site-packages/grpclib/encoding/proto.py", line 54, in decode
    return message_type.FromString(data)
  File "/worker-py/.direnv/python-3.10/lib/python3.10/site-packages/betterproto/__init__.py", line 1052, in FromString
    return cls().parse(data)
  File "pydantic/dataclasses.py", line 286, in pydantic.dataclasses._add_pydantic_validation_attributes.handle_extra_init
  File "<string>", line 4, in __init__
  File "pydantic/dataclasses.py", line 308, in pydantic.dataclasses._add_pydantic_validation_attributes.new_post_init
  File "pydantic/dataclasses.py", line 425, in pydantic.dataclasses._dataclass_validate_values
pydantic.error_wrappers.ValidationError: 1 validation error for GenerateRequest
conversation
  value is not a valid list (type=type_error.list)

proto defintion

service ReplyGenerator {
	rpc Reply(GenerateRequest) returns (stream StreamReply) {}
}

message GenerateRequest {
	repeated Message messages = 2;
}

Calling it like this from client:

async for res in service.teamlead_reply(guided_chat.GenerateRequest(messages=[])):

Compilation was done with:

PROTO_DIR=protos
GEN_DIR=generated
protofiles=$(find "${PROTO_DIR}" -name "*.proto")
python -m grpc_tools.protoc -I "${PROTO_DIR}" --python_betterproto_opt=pydantic_dataclasses --python_betterproto_out="${GEN_DIR}" ${protofiles}
主要语言
Python
星标
1.8k
派生
235
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

danielgtaylor/python-betterproto 的其他 Issue

查看 danielgtaylor/python-betterproto 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。