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

optional in protobuf not working in grpc-dart #599

Closed
yingshaoxo opened this issue Jan 17, 2023 · 2 comments
Closed

optional in protobuf not working in grpc-dart #599

yingshaoxo opened this issue Jan 17, 2023 · 2 comments

Comments

@yingshaoxo
Copy link

What I wrote

Here is my protobuf code:

syntax = "proto3";
package account_storage_service;

option go_package = "./account_storage_service";

service AccountStorageService {
    rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
}

message CreateUserRequest {
    optional string email = 1;
}

message CreateUserResponse {
    string result = 1;
    optional string error = 2;
}

Here is my grpc build command:

protoc --dart_out=grpc:lib/generated_grpc --proto_path ../party_protocols/protocols --experimental_allow_proto3_optional account_storage_service.proto

Here is my flutter code:

CreateUserRequest createUserRequest = CreateUserRequest();
createUserRequest.email = updateUserRequest.email;

CreateUserResponse response = await client.createUser(createUserRequest,
          options: get_JWT_CallOptions_for_GRPC());
if (response.error != null && response.error != "") {
    return default_response;
}

image

What I expect

Theemail property in CreateUserRequest should be a null-safe variable, which means it could be null

The error property in CreateUserResponse should be a null-safe variable, which means it could be null

What I see is

They are all not null-able variables, it seems like the compiler ignores the optional string in the protobuf definition.

image

image

image

@yingshaoxo
Copy link
Author

I found someone did a pull, but didn't get merged yet.

google/protobuf.dart#790

@mraleph
Copy link
Member

mraleph commented Jan 17, 2023

It's a protobuf issue, so it should be handled on protobuf repositiory. I asked protobuf.dart maintainer to take a look at the PR.

That being said: we can't just make these fields nullable because that is going to be massively breaking change. It probably could be an opt-in option for the protoc.

@mraleph mraleph closed this as completed Jan 17, 2023
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