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

Unexpected behaviour with explicitly setting seconds = 0 with timedelta and using to_dict #649

Open
3 tasks done
DPham-X opened this issue Nov 27, 2024 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working investigation needed

Comments

@DPham-X
Copy link

DPham-X commented Nov 27, 2024

Summary

When using timedelta with explicitly setting the seconds to 0 the output is empty instead of being explicitly set

Reproduction Steps

>>> from datetime import timedelta
>>> from dataclasses import dataclass
>>> import betterproto
>>> 
>>> @dataclass(eq=False, repr=False)
... class TestTimeout(betterproto.Message):
...     timeout: timedelta = betterproto.message_field(1)
... 
>>> TestTimeout(timeout=timedelta(seconds=0)).to_dict()
{}
>>> from datetime import timedelta
>>> from dataclasses import dataclass
>>> import betterproto
>>> 
>>> @dataclass(eq=False, repr=False)
... class TestTimeout(betterproto.Message):
...     timeout: timedelta = betterproto.message_field(1)
... 
>>> TestTimeout(timeout=timedelta(seconds=1)).to_dict()
{'timeout': '1.000s'}

Expected Results

Output expected to be {'timeout': '0s'}

Actual Results

Output is an empty dict {}

System Information

betterproto==2.0.0b6

python 3.11

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.
@DPham-X DPham-X added bug Something isn't working investigation needed labels Nov 27, 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