Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Nested message with repeated field not in to_json when mutated after initialization

Aperta
#543 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia eseguendo la riproduzione del messaggio annidato dell’issue con betterproto 2.0.0b6 e ispeziona il percorso to_dict per include_default_values=False. Il lavoro è completato quando un campo repeated annidato modificato appare nel dict restituito, mentre i campi predefiniti invariati rimangono omessi; aggiungi una copertura di regressione per entrambi i casi se viene identificata la posizione dei test nel repository.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug investigation needed
Summary

Possibly related to #199

Given a message with a nested message field containing a repeated field, if the field is mutated (eg. via list.append) after initialization, to_dict will not include it.

Reproduction Steps

Given a proto schema like this

syntax = "proto3";

message RootMessage {
  NestedMessage nested = 1;
}

message NestedMessage {
  repeated string content = 1;
}

Running the following script

message = RootMessage()

message.nested.content.append("test-content")

print("Including default values: True")
pprint(message.to_dict(include_default_values=True))

print("Including default values: False")
pprint(message.to_dict(include_default_values=False))

will result in:

Including default values: True
{'nested': {'content': ['test-content']}}

Including default values: False
{}
Expected Results

I would expect the content field of the nested message to appear in the returned dict also when include_default_values is set to False, as its content was mutated and it's no longer the default value.

Actual Results

to_dict returns an empty dict

System Information
libprotoc 3.21.6
Python 3.10.13
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: [email protected]
License: MIT
Location: /home/marco/.local/share/rtx/installs/python/3.10.13/lib/python3.10/site-packages
Requires: grpclib, python-dateutil
Required-by: 
Checklist
  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.
Lingua principale
Python
Stelle
1.8k
Fork
235
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di danielgtaylor/python-betterproto

Tutte le issue di danielgtaylor/python-betterproto

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.