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

google.protobuf.Value NullValue is replaced by undefined in fromPartial method of parent message #1137

Open
simonenkoav opened this issue Nov 19, 2024 · 1 comment

Comments

@simonenkoav
Copy link

We have proto message Parent like this:

message Parent {
    string name = 1;
    google.protobuf.Value value = 2;
}

and ts-proto generates this:

export interface Parent {
  name: string;
  value: any | undefined;
}

When request is sent to the server fromPartial method is called, I guess generation for this is here:

${requestMessage}.fromPartial(request),

which looks like this:

fromPartial<I extends Exact<DeepPartial<Parent>, I>>(object: I): Parent {
    const message = createBaseParent();
    message.name = object.name ?? "";
    message.value = object.value ?? undefined;  // <--- here
    return message;
}

so value=null is replaced by undefined (I guess because of this line

return code`${from}`;
), so when encoding in Parent.encode:

encode(message: Parent, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.name !== "") {
      writer.uint32(10).string(message.name);
    }
    if (message.value !== undefined) {
      Value.encode(Value.wrap(message.value), writer.uint32(18).fork()).join();  // <--- here
    }
    return writer;
}

null value is not wrapped, so server receives null instead of NullValue.

Could you please support correct handling of null values in fromPartial?

@simonenkoav simonenkoav changed the title google.protobuf.Value NullValue is replaced by undefined fromPartial method of parent message google.protobuf.Value NullValue is replaced by undefined in fromPartial method of parent message Nov 19, 2024
@stephenh
Copy link
Owner

stephenh commented Dec 1, 2024

Hi @simonenkoav , thanks for filing the issue!

Honestly it sounds like you've done a great job of dissecting what is going wrong--if you could turn those insights into a PR that fixes the issue, that would be amazing!

Sorry for the late reply, and the ask for a PR, but that's just realistically how ts-proto keeps evolving/getting better, is our users turning into contributors (even if it's only for one-time PRs) and slowly helping it get better and better. Thanks!

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