[ 
https://issues.apache.org/jira/browse/THRIFT-6111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dmytro Shteflyuk updated THRIFT-6111:
-------------------------------------
    Fix Version/s: 0.25.0

> Ruby Struct equality should be symmetric across generated classes
> -----------------------------------------------------------------
>
>                 Key: THRIFT-6111
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6111
>             Project: Thrift
>          Issue Type: Bug
>          Components: Ruby - Library
>            Reporter: Dmytro Shteflyuk
>            Assignee: Dmytro Shteflyuk
>            Priority: Major
>             Fix For: 0.25.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> h3. Problem
> {{Thrift::Struct#==}} compares only the fields declared by the receiver. When 
> two different generated struct classes have overlapping field names, a value 
> of the narrower class can compare equal to a value of the wider class, while 
> the reverse comparison is false.
> This violates the symmetry expected of Ruby equality: if {{a == b}} is true, 
> then {{b == a}} must also be true.
> h3. Client impact
> Applications can compare values from different generated Thrift types in 
> caching, deduplication, validation, or business logic. The current result 
> depends on operand order, so equivalent comparisons can make opposite 
> decisions. It also disagrees with the class-aware semantics already used by 
> {{eql?}} and {{hash}}.
> h3. Reproduction
> {code:ruby}
> # A has: optional string shared
> # B has: optional string shared, optional string extra
> a = A.new(shared: "value")
> b = B.new(shared: "value", extra: "different")
> [a == b, b == a]
> # current:  [true, false]
> # desired:  [false, false]
> {code}
> h3. Expected behavior
> {{==}} should compare generated Thrift struct values only when both operands 
> have the same generated class, then compare that class's declared fields. 
> This restores symmetric equality and aligns {{==}} with {{eql?}} and {{hash}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to