danielgtaylor / danielgtaylor/python-betterproto
to_dict() fails to write boolean fields without default when value is False
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 234
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
When you have a message with a boolean value as follows:
```
message Patient {
bool isRnaAvailable = 1;
}
```
then an object like
```
patient = Patient()
patient.is_rna_available = np.random.choice([True, False], 1)[0]
```
fails to write the `is_rna_available` field when it is False when calling `patient.to_dict()`, this does not happen when the value is True.
The issue seems to be in line 824 of file `betterproto/__init__py` where it runs the following comparison `elif v != self._get_field_default(field, meta) or include_default_values:`. It should be something like 'elif v != None or include_default_values', otherwise when you set a field to the same value as the default value and do not set `include_default values` then it is not written. This may be also the case for other types.
Guía de contribución
Línea de trabajo
Comienza en betterproto/__init__.py, en la lógica de to_dict() alrededor de la línea 824, y reproduce el ejemplo Patient con is_rna_available establecido en False. Comprueba cómo se gestionan los campos iguales a sus valores predeterminados, incluidos otros tipos de campo, y verifica que el diccionario resultante conserve los valores False asignados explícitamente sin requerir include_default_values.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100