From d246bf20ed30047f9b285dcc3378f9c324ed938e Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 19 Dec 2019 22:27:27 -0800 Subject: [PATCH] sharding: Tolerate blank limits when listing Otherwise, we can 500 with ValueError: invalid literal for int() with base 10: '' Change-Id: I35614aa4b42e61d97929579dcb16f7dfc9fef96f --- swift/proxy/controllers/container.py | 2 +- test/unit/proxy/controllers/test_container.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/swift/proxy/controllers/container.py b/swift/proxy/controllers/container.py index bcbe58c350..6ab0ada3a7 100644 --- a/swift/proxy/controllers/container.py +++ b/swift/proxy/controllers/container.py @@ -159,7 +159,7 @@ class ContainerController(Controller): return resp objects = [] - req_limit = int(req.params.get('limit', CONTAINER_LISTING_LIMIT)) + req_limit = int(req.params.get('limit') or CONTAINER_LISTING_LIMIT) params = req.params.copy() params.pop('states', None) req.headers.pop('X-Backend-Record-Type', None) diff --git a/test/unit/proxy/controllers/test_container.py b/test/unit/proxy/controllers/test_container.py index e393472c4a..b989fb6145 100644 --- a/test/unit/proxy/controllers/test_container.py +++ b/test/unit/proxy/controllers/test_container.py @@ -640,7 +640,7 @@ class TestContainerController(TestRingBase): self.check_response(resp, root_resp_hdrs, expected_objects=expected_objects) - # GET all objects in reverse + # GET all objects in reverse and *blank* limit mock_responses = [ # status, body, headers (200, list(reversed(sr_dicts)), root_shard_resp_hdrs), @@ -653,7 +653,7 @@ class TestContainerController(TestRingBase): expected_requests = [ # path, headers, params ('a/c', {'X-Backend-Record-Type': 'auto'}, - dict(states='listing', reverse='true')), + dict(states='listing', reverse='true', limit='')), (wsgi_quote(str_to_wsgi(shard_ranges[4].name)), {'X-Backend-Record-Type': 'auto'}, dict(marker='', end_marker='\xf0\x9f\x8c\xb4', states='listing', @@ -683,7 +683,8 @@ class TestContainerController(TestRingBase): resp = self._check_GET_shard_listing( mock_responses, list(reversed(expected_objects)), - expected_requests, query_string='?reverse=true', reverse=True) + expected_requests, query_string='?reverse=true&limit=', + reverse=True) # root object count will overridden by actual length of listing self.check_response(resp, root_resp_hdrs, expected_objects=expected_objects) @@ -831,7 +832,7 @@ class TestContainerController(TestRingBase): % (marker, end_marker, limit)) self.check_response(resp, root_resp_hdrs) - # reverse with marker, end_marker + # reverse with marker, end_marker, and limit expected_objects.reverse() mock_responses = [ (200, sr_dicts[3:4], root_shard_resp_hdrs),