protocolbuffers / protocolbuffers/protobuf
Cannot assign an array to a repeated field in Ruby
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 72k
- Forks
- 16.3k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 140
Description
What language does this apply to?
Ruby
Describe the problem you are trying to solve.
Consider trying to do this:
#!/usr/bin/ruby
require 'google/protobuf'
Google::Protobuf::DescriptorPool.generated_pool.build do
add_file("google/ads/googleads/v2/services/campaign_budget_service.proto", :syntax => :proto3) do
add_message "google.ads.googleads.v2.services.MutateCampaignBudgetsRequest" do
optional :customer_id, :string, 1
repeated :operations, :message, 2, "google.ads.googleads.v2.services.CampaignBudgetOperation"
end
add_message "google.ads.googleads.v2.services.CampaignBudgetOperation" do
oneof :operation do
optional :remove, :string, 1
end
end
end
end
module Google
module Ads
module GoogleAds
module V2
module Services
MutateCampaignBudgetsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.ads.googleads.v2.services.MutateCampaignBudgetsRequest").msgclass
CampaignBudgetOperation = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.ads.googleads.v2.services.CampaignBudgetOperation").msgclass
end
end
end
end
end
include Google::Ads::GoogleAds::V2::Services
def main
r = MutateCampaignBudgetsRequest.new
r.operations = [CampaignBudgetOperation.new]
end
if __FILE__ == $0
main
end
currently protobuf gives this error:
Traceback (most recent call last):
2: from hi.rb:40:in `<main>'
1: from hi.rb:36:in `main'
hi.rb:36:in `method_missing': Expected repeated field array (Google::Protobuf::TypeError)
Describe the solution you'd like
Assigning an array to a repeated field should work if all the values are of the right type
Describe alternatives you've considered
N/A
Additional context
my ldap pnlpn@ for on-corp discussions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Ruby reproduction in the issue and trace the repeated-field assignment path in the protobuf Ruby runtime. Confirm the behavior with an array containing a CampaignBudgetOperation, then identify or add the relevant Ruby tests; done means valid arrays assign without Google::Protobuf::TypeError while invalid element types remain rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100