googleapis / googleapis/google-cloud-java

[sdk-platform-java] Auto-population of a field should not occur if a field has explicit presence and is set to the default value

Đang mở
#12,449 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
priority: p4 type: bug
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

The current implementation for autopopulation of a field assumes that if the field is an empty string or not set (and all other requirements are fulfilled), that the field should be autopopulated.

Per https://google.aip.dev/client-libraries/4235:

```
The field must be automatically populated if and only if one of the following conditions holds:

The field supports explicit presence, and has not been set by the user
```

Digging in a little - a field in proto3 supports explicit presence if it is explicitly annotated as `optional` (https://protobuf.dev/programming-guides/field_presence/#presence-in-proto3-apis).
Proto2 supports explicit presence by default, but GAPIC libraries require proto3 by default, so I don't think we need to check for proto2 vs. proto3.
Additionally, proto3 supports explicit presence as of [v3.15.0](https://github.com/protocolbuffers/protobuf/releases/tag/v3.15.0). Since we're already using a much newer version of proto3, I don't think we need to check for any older versions of proto3.

Note that being annotated as `optional` is *not* a requirement for autopopulation - the requirement is simply that the field is *not* marked as `required`.

Therefore, there exists an edge case where:

1) a string field `foo` is explicitly annotated as `optional`
2) a user sets `foo` to the value of an empty string

and the expected outcome is that `foo` is *not* autopopulated.

A potential path forward would be to:

1) Check for the explicit `optional` annotation of a field and add it as an attribute to `Field`
2) If that attribute is true, update the generated code to:

```
if(!request.hasRequestId())
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.