Enforce serialize_empty
for repeated fields (#417)
This commit is contained in:
parent
8fbf4476a8
commit
bfc0fac754
@ -806,6 +806,7 @@ class Message(ABC):
|
||||
meta.proto_type,
|
||||
item,
|
||||
wraps=meta.wraps or "",
|
||||
serialize_empty=True,
|
||||
)
|
||||
# if it's an empty message it still needs to be represented
|
||||
# as an item in the repeated list
|
||||
|
12
tests/inputs/regression_387/regression_387.proto
Normal file
12
tests/inputs/regression_387/regression_387.proto
Normal file
@ -0,0 +1,12 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package regression_387;
|
||||
|
||||
message Test {
|
||||
uint64 id = 1;
|
||||
}
|
||||
|
||||
message ParentElement {
|
||||
string name = 1;
|
||||
repeated Test elems = 2;
|
||||
}
|
12
tests/inputs/regression_387/test_regression_387.py
Normal file
12
tests/inputs/regression_387/test_regression_387.py
Normal file
@ -0,0 +1,12 @@
|
||||
from tests.output_betterproto.regression_387 import (
|
||||
ParentElement,
|
||||
Test,
|
||||
)
|
||||
|
||||
|
||||
def test_regression_387():
|
||||
el = ParentElement(name="test", elems=[Test(id=0), Test(id=42)])
|
||||
binary = bytes(el)
|
||||
decoded = ParentElement().parse(binary)
|
||||
assert decoded == el
|
||||
assert decoded.elems == [Test(id=0), Test(id=42)]
|
9
tests/inputs/regression_414/regression_414.proto
Normal file
9
tests/inputs/regression_414/regression_414.proto
Normal file
@ -0,0 +1,9 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package regression_414;
|
||||
|
||||
message Test {
|
||||
bytes body = 1;
|
||||
bytes auth = 2;
|
||||
repeated bytes signatures = 3;
|
||||
}
|
15
tests/inputs/regression_414/test_regression_414.py
Normal file
15
tests/inputs/regression_414/test_regression_414.py
Normal file
@ -0,0 +1,15 @@
|
||||
from tests.output_betterproto.regression_414 import Test
|
||||
|
||||
|
||||
def test_full_cycle():
|
||||
body = bytes([0, 1])
|
||||
auth = bytes([2, 3])
|
||||
sig = [b""]
|
||||
|
||||
obj = Test(body=body, auth=auth, signatures=sig)
|
||||
|
||||
decoded = Test().parse(bytes(obj))
|
||||
assert decoded == obj
|
||||
assert decoded.body == body
|
||||
assert decoded.auth == auth
|
||||
assert decoded.signatures == sig
|
Loading…
x
Reference in New Issue
Block a user