From 12fc2eefd35a9232dab251ef5266be23555937c5 Mon Sep 17 00:00:00 2001 From: Stephen Martin Date: Tue, 15 May 2018 17:06:55 -0700 Subject: [PATCH 1/3] count deleted by total_records --- kinto/core/resource/__init__.py | 3 +-- tests/core/resource/test_pagination.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/kinto/core/resource/__init__.py b/kinto/core/resource/__init__.py index c07056f6c..8ed4258cb 100644 --- a/kinto/core/resource/__init__.py +++ b/kinto/core/resource/__init__.py @@ -397,8 +397,7 @@ def collection_delete(self): self._add_timestamp_header(self.request.response, timestamp=timestamp) # Add pagination header - offset = offset + len(deleted) - if limit and len(deleted) == limit and offset < total_records: + if limit and len(deleted) == limit and total_records > 1: next_page = self._next_page_url(sorting, limit, lastrecord, offset) self.request.response.headers['Next-Page'] = next_page else: diff --git a/tests/core/resource/test_pagination.py b/tests/core/resource/test_pagination.py index 42e9ac8c8..8c4124421 100644 --- a/tests/core/resource/test_pagination.py +++ b/tests/core/resource/test_pagination.py @@ -239,6 +239,24 @@ def test_return_total_records_in_headers_matching_deletable(self): count = headers['Total-Records'] self.assertEquals(int(count), 20) + def test_paginated_delete_second_to_last_gets_next_header(self): + all_records = self.resource.collection_get() + get_all_headers = self.last_response.headers + count = int(get_all_headers['Total-Records']) - 1 + + self.validated['querystring'] = {'_limit': 1} + headers = [] + for i in range(count): + self.resource.collection_delete() + headers.append(self.last_response.headers) + self._setup_next_page() + + self.resource.collection_delete() + headers.append(self.last_response.headers) + + self.assertIn('Next-Page', headers[count - 1]) + self.assertNotIn('Next-Page', headers[count]) + def test_token_cannot_be_reused_twice(self): self.resource.request.method = "DELETE" self.validated['querystring']['_limit'] = 3 From c40ae8a54d30dc209b08fdf3abaafe152365a695 Mon Sep 17 00:00:00 2001 From: Stephen Martin Date: Tue, 15 May 2018 17:29:29 -0700 Subject: [PATCH 2/3] fix test --- tests/core/resource/test_pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/resource/test_pagination.py b/tests/core/resource/test_pagination.py index 8c4124421..76a70db7d 100644 --- a/tests/core/resource/test_pagination.py +++ b/tests/core/resource/test_pagination.py @@ -240,7 +240,7 @@ def test_return_total_records_in_headers_matching_deletable(self): self.assertEquals(int(count), 20) def test_paginated_delete_second_to_last_gets_next_header(self): - all_records = self.resource.collection_get() + self.resource.collection_get() get_all_headers = self.last_response.headers count = int(get_all_headers['Total-Records']) - 1 From 1f11018c3b10d7643f396aaf004432c3f7c28ea5 Mon Sep 17 00:00:00 2001 From: Stephen Martin Date: Tue, 15 May 2018 18:50:35 -0700 Subject: [PATCH 3/3] add changelog entry --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 710b7c7e5..8bf1bda3f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,7 @@ This document describes changes between each past release. ------------------ - Batch endpoint now checks for and aborts any parent request if subrequest encounters 409 constraint violation (fixes #1569) +- Fix a bug where you could not reach the last records via Next-Header when deleting with pagination (fixes #1170) 9.0.0 (2018-04-25) ------------------