Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
AdrienVannson opened this issue Sep 17, 2024 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working investigation needed

Comments

@AdrienVannson
Copy link
Contributor

AdrienVannson commented Sep 17, 2024

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.
@AdrienVannson AdrienVannson added bug Something isn't working investigation needed labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation needed
Projects
None yet
Development

No branches or pull requests

1 participant