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

Abierto
#12,449 2 comentarios 0 reacciones 0 asignados Ver en GitHub
priority: p4 type: bug
Lenguaje dominante
Java
Estrellas
2.1k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
154

Descripción

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())
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.