Skip to content

Error when calling to_pydict on a message having a repeated timestamp field #617

Open
@AdrienVannson

Description

@AdrienVannson

When calling the to_pydict method on a message which has a repeated timestamp field, an AttributeError is raised.

Reproduction Steps

Compile the following message :

message Msg {
    repeated google.protobuf.Timestamp ts = 1;
}

Then, execute the following code:

from datetime import datetime

msg = Msg(ts=[datetime(2015, 3, 5)])

print(msg.to_dict())
print(msg.to_pydict())

Expected Results

In this situation, it is expected for the two calls to work without error.

Actual Results

The call to to_dict works as expected: it prints {'ts': ['2015-03-05T00:00:00Z']}. However, the call to to_pydict fails with the error: AttributeError: 'datetime.datetime' object has no attribute 'to_pydict'.

It is possible to simply fix this bug (and the related bugs) by patching the to_pydict function, but it might be easier with a bit of refactoring first. I will probably be able to work on this once my other PRs are approved.

System Information

libprotoc 3.12.4
Python 3.12.5
Name: betterproto
Version: 2.0.0b7
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: XXX/.venv/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: pygrpc-poc

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions