Skip to content

optional is not working, it doesn't allow me to set a field to null #11790

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

Closed
yingshaoxo opened this issue Feb 3, 2023 · 6 comments
Closed

Comments

@yingshaoxo
Copy link

As I tested out, the Python, Javascript/Typescript, Rust, Dart, they all support or about to support optional filed to null.

Why Java and Cpp can't do that?

grpc/grpc-java#9868

@yingshaoxo yingshaoxo added the untriaged auto added to all issues by default when created. label Feb 3, 2023
@v-chernyshev
Copy link

I'm not a maintainer, but everything works as designed here, null values are not allowed. optional instructs the compiler to generate the has* methods for the corresponding fields.

@yingshaoxo
Copy link
Author

Then why python,javascript,rust, they support null?

If java do not support it, then nobody would use java to communicate with python,javascript/typescript,rust,dart by using grpc

@v-chernyshev
Copy link

Null fields do not exist in protobuf. Getters, for example, should never return null, irrespective of the language. Please note that a similar question has already been asked before and the official advice is to rely on the clear* methods to get a consistent behaviour.

@yingshaoxo
Copy link
Author

Could you guys make a simple logic check like this:

def a_set_function(value):
    if value == null:
        call clear* method, so that property won't exist in the response (return value)

And in the client side, the program will do this:

if protocol optional definition fields not exists in the return value, it sets that field to null

@esorot
Copy link
Contributor

esorot commented Feb 13, 2023

This is working as intended. Feel free to create a PR with your intended changes where we can review.

@esorot esorot closed this as completed Feb 13, 2023
@wirekang
Copy link

This is so weird. Some language implementations treat optional as nullable but some is not.

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

No branches or pull requests

5 participants