question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assignment of item at index in repeated field

See original GitHub issue

With a normal Python list we can do:

l = [1, 2, 3, 4, 5]
l[1] = 'hello'
print(l)
> [1, 'hello', 3, 4, 5]

However for a repeated field of a message wrapped by proto-plus we see slightly different behavior:

l = [1, 2, 3, 4, 5]
l[1] = 'hello'
print(l)
> [1, 'hello', 2, 3, 4, 5]

Notice how the 2 just gets push back an index instead of overridden.

For a raw protobuf message, we would normally do:

l = [1, 2, 3, 4, 5]
l[1].CopyFrom('hello')
print(l)
> [1, 'hello', 3, 4, 5]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
software-dovcommented, Feb 18, 2021

I took a look through the unit tests, and it seems that this exact situation is tested for (with the correct behavior expected). I think this is a somewhat recent addition by a third party contributor, thought. I will get the change packaged and out soon and see if that solves the problem.

1reaction
BenRKarlcommented, Feb 19, 2021

Thanks @0x2b3bfa0 #178 does indeed appear to fix our issue.

@software-dov how soon do you think until 1.13.1 will get published to PyPi?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to assign to repeated field? - python - Stack Overflow
I get an error: Assigment not allowed for repeated field "id" in protocol message object How to assign a value to a repeated...
Read more >
repeated_field.h | Protocol Buffers - Google Developers
RepeatedField is used to represent repeated fields of a primitive type (in other ... Set(int index, const Element & value) ... Assign(Iter begin,...
Read more >
Assignment with Repeated Indices - MathWorks Blogs
Repeated Indices with a Single Assignment. I initialize an output matrix to zeros and create two vectors, one with locations (indices) and ...
Read more >
Class RepeatedField<T> (3.15.8) | .NET client library
Creates a deep clone of this repeated field. ... If the field type is a message type, each element is also cloned; otherwise,...
Read more >
Repeated fields - Embedded Proto
To access the array and the elements in the repeated field various functions are generated in the message.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found