python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Empty list cannot be parsed by `repeated`

Open clotodex opened this issue 2 years ago • 1 comments

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}

clotodex avatar Jul 10 '23 14:07 clotodex

Still an issue.

coderanger avatar Jun 20 '24 19:06 coderanger