From 6ec4ee6dfb83b5fbcb2e107a9c59a1d7fbf3f968 Mon Sep 17 00:00:00 2001 From: patrick thornton Date: Fri, 22 May 2026 14:45:03 -0400 Subject: [PATCH] fix: unwrap [parsed_page, raw_response] tuple in pagination iterators Generated paginated endpoints now return a [parsed_page, raw_response] tuple from the request block (to expose HTTP response metadata), but the iterators in lib/auth0/internal/iterators/ are frozen via .fernignore and were still calling page.send(@item_field) on the raw block result. With a tuple this hits Array#send, surfacing as e.g. `undefined method 'network_acls' for an instance of Array` across all list endpoints. Mirror the fix from the upstream iterator templates: accept either the parsed page directly or a [parsed_page, raw_response] tuple, and use the first element when an Array is returned. Applied to offset_page_iterator.rb (extracted into a private fetch_page helper used at both call sites) and cursor_page_iterator.rb (inline at the single call site). Test results on this branch: 511 runs, 4982 assertions, 0 failures, 0 errors (previously 58 errors, all originating from offset_page_iterator.rb:69 / cursor_page_iterator.rb:46). --- .../internal/iterators/cursor_page_iterator.rb | 11 +++++++++-- .../internal/iterators/offset_page_iterator.rb | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/auth0/internal/iterators/cursor_page_iterator.rb b/lib/auth0/internal/iterators/cursor_page_iterator.rb index 07af7037..bae8da6d 100644 --- a/lib/auth0/internal/iterators/cursor_page_iterator.rb +++ b/lib/auth0/internal/iterators/cursor_page_iterator.rb @@ -37,12 +37,19 @@ def next? # Retrieves the next page from the API. # - # @return [Boolean] + # @return [Object, nil] def next_page return if !@need_initial_load && @cursor.nil? @need_initial_load = false - fetched_page = @get_next_page.call(@cursor) + result = @get_next_page.call(@cursor) + # The block returns either the parsed page directly, or a + # [parsed_page, raw_http_response] tuple. Unwrap accordingly. + fetched_page = if result.is_a?(Array) + result[0] + else + result + end @cursor = fetched_page.send(@cursor_field) fetched_page end diff --git a/lib/auth0/internal/iterators/offset_page_iterator.rb b/lib/auth0/internal/iterators/offset_page_iterator.rb index acadaf4b..af1858e2 100644 --- a/lib/auth0/internal/iterators/offset_page_iterator.rb +++ b/lib/auth0/internal/iterators/offset_page_iterator.rb @@ -43,7 +43,7 @@ def next? return @has_next_page unless @has_next_page.nil? return true if @next_page - fetched_page = @get_next_page.call(@page_number) + fetched_page = fetch_page(@page_number) fetched_page_items = fetched_page&.send(@item_field) if fetched_page_items.nil? || fetched_page_items.empty? @has_next_page = false @@ -61,7 +61,7 @@ def next_page this_page = @next_page @next_page = nil else - this_page = @get_next_page.call(@page_number) + this_page = fetch_page(@page_number) end @has_next_page = this_page&.send(@has_next_field) if @has_next_field @@ -78,6 +78,20 @@ def next_page this_page end + + private + + # The block returns either the parsed page directly, or a + # [parsed_page, raw_http_response] tuple. Unwrap accordingly. + def fetch_page(page_number) + result = @get_next_page.call(page_number) + if result.is_a?(Array) + fetched_page, _raw_response = result + fetched_page + else + result + end + end end end end