google-ads-ruby
google-ads-ruby copied to clipboard
Unexpected enumerable response behaviour
Using v6 of the api and the search service, using the same search_query
and customer_id
in both scenari.
response = search_service.search(customer_id: customer_id, query: search_query)
response.count
=> 1
response.first
=> nil
response.to_a
=> []
response = search_service.search(customer_id: customer_id, query: search_query)
response.any?
=> true
response.first
=> <Google::Ads::GoogleAds::V6::Services::GoogleAdsRow: ...
response.to_a
=> [<Google::Ads::GoogleAds::V6::Services::GoogleAdsRow ...
response.to_a
=> []
I think the query is irrelevant here, the points are:
- if I use
count
it seems to flush the results - if I use
to_a
twice, it seems to flush the results
Not all the results are returned immediately, and there may be more requests made behind the scenes as you iterate through the results. Calling anything that will force an iteration through all results will effectively exhaust the iterator. So if you want to process the results and also do one of these kinds of operations, you'll need to do both together in a single pass.
I don't think there's anything we could do to fix the behavior, but I will look at trying to update our documentation for the library to explicitly mention this.
I understand the ins and outs. Thank you