[ 
https://issues.apache.org/jira/browse/THRIFT-735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12845728#action_12845728
 ] 

Bryan Duxbury commented on THRIFT-735:
--------------------------------------

It's not an assumption - it's a guarantee. Only when dealing with languages 
that don't implement unions directly is that an "assumption".

Maybe part of the problem is that we're not in agreement about the nature of 
unions. In my use case, I definitely want "exactly one" in a required-like 
fashion. It sounds like you want to offer "zero or one". This sounds like the 
difference between an "optional" union and a "required" union. We currently 
don't support this distinction - rather, we just have "required" unions. 

If this formulation is correct, then I'd suggest that the way to achieve this 
is to let the field's required or optional modifier specify the "zero" 
possibility (through unset fields) and required specify the "exactly one". I 
think this will most support users' expectations.

Indeed, adding a new value to an enum IS dangerous. If two different consumers 
have different conceptions about the valid contents of an enum, then one side 
can reject a value as invalid, leading to an identical situation. I don't think 
this is a problem - Thrift will skip it in the optional case and complain in 
the required case. Again, the onus is on the schema designer to specify, 
through optional/required, whether they can tolerate missing values in given 
fields.

> Required field checking is broken when the field type is a Union struct
> -----------------------------------------------------------------------
>
>                 Key: THRIFT-735
>                 URL: https://issues.apache.org/jira/browse/THRIFT-735
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java), Library (Java)
>    Affects Versions: 0.2
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-735.patch
>
>
> The validate() method on generated structs verifies that required fields are 
> set after validation. However, if the type of the field is a Union struct, 
> then just checking that the field isn't null is not a valid check. The value 
> may be a non-null union, but have an unset field. (We encountered this when 
> deserializing a type that had a union for a field, and the union's set value 
> was an enum value that had been removed from the definition, making it a 
> skip.)
> In order to perform the correct validation, if the value is a Union, then we 
> must also check that the set field and value are non-null.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to