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

Fix handling of optional fields in coerce #954

Merged
merged 1 commit into from
May 30, 2023
Merged

Conversation

psyho
Copy link
Contributor

@psyho psyho commented May 30, 2023

A field that appears in a Hash as nil breaks coercing the Hash with an error like: "Value must be a Hash or a Foo (ArgumentError)".

For example, the version 0.19.0 of gapic-common breaks google-cloud-firestore.

Running this:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'dotenv'
  gem 'gapic-common', '0.19.0'
  gem 'google-cloud-firestore', '2.13.0'
end

require 'dotenv/load'
require 'google/cloud/firestore'

firestore = Google::Cloud::Firestore.new(project_id: ENV.fetch('PROJECT_ID'))
doc = firestore.doc(ENV.fetch('DOCUMENT_ID'))
puts doc.get

Results in an error like:

/home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/gapic-common-0.19.0/lib/gapic/protobuf.rb:39:in `coerce': Value  must be a Hash or a Google::Cloud::Firestore::V1::DocumentMask (ArgumentError)
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/gapic-common-0.19.0/lib/gapic/protobuf.rb:99:in `coerce_submessage'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/gapic-common-0.19.0/lib/gapic/protobuf.rb:61:in `block in coerce_submessages'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/gapic-common-0.19.0/lib/gapic/protobuf.rb:57:in `each'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/gapic-common-0.19.0/lib/gapic/protobuf.rb:57:in `coerce_submessages'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/gapic-common-0.19.0/lib/gapic/protobuf.rb:41:in `coerce'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/google-cloud-firestore-v1-0.10.0/lib/google/cloud/firestore/v1/firestore/client.rb:749:in `batch_get_documents'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/google-cloud-firestore-2.13.0/lib/google/cloud/firestore/service.rb:74:in `get_documents'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/google-cloud-firestore-2.13.0/lib/google/cloud/firestore/client.rb:348:in `get_all'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/google-cloud-firestore-2.13.0/lib/google/cloud/firestore/document_reference.rb:168:in `each'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/google-cloud-firestore-2.13.0/lib/google/cloud/firestore/document_reference.rb:168:in `first'
        from /home/psyho/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/google-cloud-firestore-2.13.0/lib/google/cloud/firestore/document_reference.rb:168:in `get'
        from ./gapic:18:in `<main>'

@psyho psyho requested a review from a team as a code owner May 30, 2023 09:30
A field that appears in a Hash as nil breaks coercing the Hash with an
error like: "Value  must be a Hash or a Foo (ArgumentError)"
Copy link
Member

@dazuma dazuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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 this pull request may close these issues.

2 participants