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

Unexpected enumerable response behaviour #290

Open
apneadiving opened this issue Mar 10, 2021 · 2 comments
Open

Unexpected enumerable response behaviour #290

apneadiving opened this issue Mar 10, 2021 · 2 comments
Labels
docs improvement Improvement to the documentation in the code or repository markdown files

Comments

@apneadiving
Copy link
Contributor

apneadiving commented Mar 10, 2021

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
@mcloonan
Copy link
Member

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.

@mcloonan mcloonan added the docs improvement Improvement to the documentation in the code or repository markdown files label Mar 22, 2021
@apneadiving
Copy link
Contributor Author

I understand the ins and outs. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs improvement Improvement to the documentation in the code or repository markdown files
Projects
None yet
Development

No branches or pull requests

2 participants