danielgtaylor / danielgtaylor/python-betterproto

Error when calling to_pydict on a message having a repeated timestamp field

Abierto
#617 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug investigation needed
Lenguaje dominante
Python
Estrellas
1.8k
Forks
234
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

When calling the `to_pydict` method on a message which has a repeated timestamp field, an `AttributeError` is raised.

### Reproduction Steps

Compile the following message :
```
message Msg {
repeated google.protobuf.Timestamp ts = 1;
}
```

Then, execute the following code:
```python
from datetime import datetime

msg = Msg(ts=[datetime(2015, 3, 5)])

print(msg.to_dict())
print(msg.to_pydict())
```

### Expected Results

In this situation, it is expected for the two calls to work without error.

### Actual Results

The call to `to_dict` works as expected: it prints `{'ts': ['2015-03-05T00:00:00Z']}`. However, the call to `to_pydict` fails with the error: `AttributeError: 'datetime.datetime' object has no attribute 'to_pydict'`.

It is possible to simply fix this bug (and the related bugs) by patching the `to_pydict` function, but it might be easier with a bit of refactoring first. I will probably be able to work on this once my other PRs are approved.

### System Information

libprotoc 3.12.4
Python 3.12.5
Name: betterproto
Version: 2.0.0b7
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: danielgtaylor@gmail.com
License: MIT
Location: XXX/.venv/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: pygrpc-poc

### Checklist

- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Reproduce el problema con la definición de Msg y el valor datetime proporcionados; después, sigue la ruta de conversión de to_pydict que procesa repeated fields y valores de google.protobuf.Timestamp. Se considera terminado cuando to_pydict se completa sin AttributeError y devuelve la representación esperada de repeated timestamp, coincidiendo con el comportamiento funcional de to_dict.

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
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.