Skip to content

Conversation

@antstorm
Copy link
Contributor

Fixes #123

This is a weird issue, but it seems that Object#singleton_class does something to the object and screws up class detection in C extensions (used by Protobufs). Here's an example:

>> a = 'TestWorkflow'
=> "TestWorkflow"
>> a.singleton_class
=> #<Class:#<String:0x000000013320dc10>>
>> Temporal::Api::Common::V1::WorkflowType.new(name: a)
(irb):3:in `initialize': Invalid argument for string field 'name' (given String). (Google::Protobuf::TypeError)
	from (irb):3:in `new'
	from (irb):3:in `<main>'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/cli/console.rb:19:in `run'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/cli.rb:504:in `console'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/cli.rb:30:in `dispatch'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/cli.rb:24:in `start'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/exe/bundle:49:in `block in <top (required)>'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
	from /opt/homebrew/Cellar/rbenv/1.1.2/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/exe/bundle:37:in `<top (required)>'
	from /opt/homebrew/opt/rbenv/versions/3.0.1/bin/bundle:23:in `load'
	from /opt/homebrew/opt/rbenv/versions/3.0.1/bin/bundle:23:in `<main>'

Here's the root cause, but I'm not 100% sure of the underlying mechanics — https://twitter.com/ANTStorm/status/1474038270657024001

The fix just calls #singleton_method on a duplicate object avoiding any modifications to the original one.

A new integration test exposing the issue is added.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Invalid argument for string field 'name' (given String)

1 participant