Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Handling oneof that is NOT_SET #348

Open
fintara opened this issue Mar 18, 2024 · 0 comments
Open

Handling oneof that is NOT_SET #348

fintara opened this issue Mar 18, 2024 · 0 comments

Comments

@fintara
Copy link

fintara commented Mar 18, 2024

The following proto:

message MyMsg {
  bool a = 1;
  oneof b {
    bool c = 2;
    bool d = 3;
  }
}

corresponds to the following Haskell code:

data MyMsg = MyMsg
  { a :: Bool
  , b :: MyMsg_b
  }
  deriving (Eq, Show, Generic)
  deriving (ToSchema MySchema "MyMsg", FromSchema MySchema "MyMsg")

data MyMsg_b
  = MyMsg_b_c Bool
  | MyMsg_b_d Bool
  deriving (Eq, Show, Generic)

Now, according to the proto3 spec, a particular oneof may remain unset. To check this (f.e. in Python) you'd call my_msg.WhichOneof('b') - it can return None, "c" or "d".

With this library you cannot handle this very real possibility, instead you get a runtime error:

status = StatusCode.INVALID_ARGUMENT
details = "done-error: WireTypeError "unknown type in an union""
debug_error_string = "UNKNOWN:Error received from peer ipv4:127.0.0.1:21599 {grpc_message:"done-error: WireTypeError \"unknown type in an union\"", grpc_status:3, created_time:"2024-03-18T13:36:28.721508+02:00"}"

Currently it is not possible to declare the type of the b field to be Maybe MyMsg_b.

The only workaround (as I described in my previous issue #339) is to wrap the oneof in yet another message.
Now I'm pretty sure this ought to be fixed.

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

No branches or pull requests

1 participant