Skip to content

Commit 605de88

Browse files
fix: revert algorithm for RepeatedComposite insertion. (#101)
The sequence pased is referred to as a list but it is not guarantted to be a Python native list. Co-authored-by: Bob Hancock <[email protected]>
1 parent db45955 commit 605de88

File tree

1 file changed

+7
-1
lines changed
  • packages/proto-plus/proto/marshal/collections

1 file changed

+7
-1
lines changed

packages/proto-plus/proto/marshal/collections/repeated.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,10 @@ def __setitem__(self, key, value):
125125
def insert(self, index: int, value):
126126
"""Insert ``value`` in the sequence before ``index``."""
127127
pb_value = self._marshal.to_proto(self._pb_type, value, strict=True)
128-
self.pb.insert(index, pb_value)
128+
129+
# Protocol buffers does not define a useful insert, so we have
130+
# to pop everything after this point off the list and reload it.
131+
after = [pb_value]
132+
while self.pb[index:]:
133+
after.append(self.pb.pop(index))
134+
self.pb.extend(after)

0 commit comments

Comments
 (0)