Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get on repeated field erroring with TypeError #1379

Open
jack-tutor opened this issue Nov 4, 2023 · 1 comment
Open

get on repeated field erroring with TypeError #1379

jack-tutor opened this issue Nov 4, 2023 · 1 comment

Comments

@jack-tutor
Copy link

I have been encountering a problem lately where if I have a repeated field - and the given message does not populate any values in the repeated field - calling the getter for that field on that message will error:

The error looks like:

TypeError: Cannot assign to read only property '3' of object '[object Array]'

I am using a python backend to generate the messages.

For example, it would occur with protos:

message Bar {}

message Foo {
    repeated Bar bars = 1;
}

the message created as Foo(bars=[]) in python
then this:

foo.getBarsList()

would raise the TypeError - but if the message had happened to be created as Foo(bars=[Bar()]), then no error would occur.

I am running grpc-web 1.4.2, grpcio = "^1.56.0" in python, and protoc 3.20.1

I do not expect that empty repeated messages are generally broken as this would certainly have been raised as an issue if it was true - but I'm looking for potential causes, debugging steps I should execute, and creating this issue for anyone else that might run into this.

Thanks

@sampajano
Copy link
Collaborator

sampajano commented Nov 14, 2023

@jack-tutor Thanks for the report!

It does sound like a mis-behavior indeed :)

I wonder if you can, help identify the exact line of code which throws that error?

It would be helpful if you can try not further obfuscate the JS bundle using something like "development" mode (like by replacing this line).

It's ok if the line is already obfuscated, but at least we can confirm where the error is coming from.

I'd guess it's happening in the protobuf-javascript library, since from what i can tell from my manual test, the generated code would simply call into the getRepeatedWrapperField function, like below:

/**
 * repeated Bar bars = 10;
 * @return {!Array<!proto.grpc.gateway.testing.Bar>}
 */
proto.grpc.gateway.testing.EchoResponse.prototype.getBarsList = function() {
  return /** @type{!Array<!proto.grpc.gateway.testing.Bar>} */ (
    jspb.Message.getRepeatedWrapperField(this, proto.grpc.gateway.testing.Bar, 10));
};

Which is implemented below:

https://github.com/protocolbuffers/protobuf-javascript/blob/e1a52f9a897653985b0649cca17615cb1b0eb3b7/message.js#L1262-L1277

I'm guessing the error you saw happens might be happening in this line:

https://github.com/protocolbuffers/protobuf-javascript/blob/e1a52f9a897653985b0649cca17615cb1b0eb3b7/message.js#L1274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants