From 15494abecbfc18a4c433f0e51c43ff9d35b76b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Fri, 18 Aug 2023 11:29:26 -0600 Subject: [PATCH] feat: Auto-detect end of pagination --- singer_sdk/streams/rest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/singer_sdk/streams/rest.py b/singer_sdk/streams/rest.py index 378b32c732..532006e1b4 100644 --- a/singer_sdk/streams/rest.py +++ b/singer_sdk/streams/rest.py @@ -395,7 +395,14 @@ def request_records(self, context: dict | None) -> t.Iterable[dict]: resp = decorated_request(prepared_request, context) request_counter.increment() self.update_sync_costs(prepared_request, resp, context) - yield from self.parse_response(resp) + records = iter(self.parse_response(resp)) + try: + first_record = next(records) + except StopIteration: + self.logger.info("No records found in response") + break + yield first_record + yield from records paginator.advance(resp)