danielgtaylor / danielgtaylor/python-betterproto

Allow mapping google.protobuf.duration to Optional datetime.timedelta

オープン
#246 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

We had some issues loosing a zero-duration. Currently, if a serialized Protobuf message contains a 0-duration like `myDuration` in this example:
```protobuf
syntax = "proto3";

message Some {
string someField = 1;
google.protobuf.duration myDuration = 2;
}
```
and data like
```json
{
"someField": "42",
"myDuration": "0s"
}
```
this `myDuration` field gets correctly deserialized into a `timedelta(0)`. However, when forwarding/serializing that Python object again, the duration gets lost:
```json
{
"someField": "42",
// myDuration missing
}
```
Because `timedelta(0)` is the default value, it appearently represents no-value in betterProto (see [Well known Google Types](https://github.com/danielgtaylor/python-betterproto#well-known-google-types)).

Is it possible to configure the mapping from Protobuf's `duration` to an Optional timedelta value so that no-value can be distinguished from a 0-value in Python?

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。