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

Ruby message class equality changed in 3.15.0 #8427

Closed
ob-stripe opened this issue Mar 25, 2021 · 3 comments · Fixed by #8434
Closed

Ruby message class equality changed in 3.15.0 #8427

ob-stripe opened this issue Mar 25, 2021 · 3 comments · Fixed by #8434

Comments

@ob-stripe
Copy link

ob-stripe commented Mar 25, 2021

What version of protobuf and what language are you using?
Version: v3.15.0
Language: Ruby

What operating system (Linux, Windows, ...) and version?
macOS Catalina 10.15.7

What runtime / compiler are you using (e.g., python version or gcc version)
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]

What did you do?
Run the following Ruby script:

require "google/protobuf"

Google::Protobuf::DescriptorPool.generated_pool.build do
  add_file("foo.proto", :syntax => :proto3) do
    add_message "Foo" do
      optional :type, :enum, 1, "Foo.Type"
    end
    add_enum "Foo.Type" do
      value :TYPE_FOO_ZERO, 0
      value :TYPE_FOO_ONE, 1
    end
    add_message "Bar" do
      optional :type, :enum, 1, "Bar.Type"
    end
    add_enum "Bar.Type" do
      value :TYPE_BAR_ZERO, 0
      value :TYPE_BAR_ONE, 1
    end
  end
end

Foo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Foo").msgclass
Bar = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Bar").msgclass

foo = Foo.new(type: :TYPE_FOO_ONE)
p foo

bar = Bar.new(type: :TYPE_BAR_ONE)
p bar

p foo == bar

What did you expect to see
With google-protobuf 3.14.0, the script returns:

<Foo: type: :TYPE_FOO_ONE>
<Bar: type: :TYPE_BAR_ONE>
false

What did you see instead?
With google-protobuf 3.15.0, the script returns:

<Foo: type: :TYPE_FOO_ONE>
<Bar: type: :TYPE_BAR_ONE>
true

I assume the new behavior is due to the fact that the two messages have the same Proto serialization ("\b\x01" in both cases), but I think the previous behavior was more correct. Generally, comparing two instances of different classes should return false. Even ignoring that, the inner enum types are different. Just because the numerical values happen to be the same does not mean the messages are equal.

Anything else we should know about your project / environment
N/A

@ob-stripe
Copy link
Author

Note that the latest version 3.15.6 behaves the same as 3.15.0.

@haberman
Copy link
Member

I believe the fix here is just to also compare the classes of the messages. I'll write up a fix.

@haberman
Copy link
Member

haberman commented Apr 3, 2021

Fix is released in https://github.com/protocolbuffers/protobuf/releases/tag/v3.15.7

@haberman haberman closed this as completed Apr 3, 2021
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

Successfully merging a pull request may close this issue.

2 participants