summaryrefslogtreecommitdiffstats
path: root/testapi
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-08-21 18:54:07 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-08-21 18:59:49 +0800
commit30868451cb3a59bf364a82854079e97e272d1438 (patch)
tree0ad56159606ce1f93610cf436fb75599f850c892 /testapi
parent1d05aa834b397df4156c064b9eeabf012f944250 (diff)
bugfix: OperationFailure: the limit must be positive
in cursor.aggregate(), set limit=0 is not allowed, in this patch, if no records to be listed, return empty list directly, no more aggregate() JIRA: RELENG-293 Change-Id: I7317892875da9c0f785ba010b55715032dee31ce Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi')
-rw-r--r--testapi/opnfv_testapi/resources/handlers.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/testapi/opnfv_testapi/resources/handlers.py b/testapi/opnfv_testapi/resources/handlers.py
index 474a203..73afabe 100644
--- a/testapi/opnfv_testapi/resources/handlers.py
+++ b/testapi/opnfv_testapi/resources/handlers.py
@@ -110,22 +110,23 @@ class GenericApiHandler(web.RequestHandler):
pipelines.append({'$match': query})
total_pages = 0
- if page > 0:
- cursor = dbapi.db_list(self.table, query)
- records_count = yield cursor.count()
- total_pages, return_nr = self._calc_total_pages(records_count,
- last,
- page,
- per_page)
- pipelines = self._set_pipelines(pipelines,
- sort,
- return_nr,
- page,
- per_page)
- cursor = dbapi.db_aggregate(self.table, pipelines)
data = list()
- while (yield cursor.fetch_next):
- data.append(self.format_data(cursor.next_object()))
+ cursor = dbapi.db_list(self.table, query)
+ records_count = yield cursor.count()
+ if records_count > 0:
+ if page > 0:
+ total_pages, return_nr = self._calc_total_pages(records_count,
+ last,
+ page,
+ per_page)
+ pipelines = self._set_pipelines(pipelines,
+ sort,
+ return_nr,
+ page,
+ per_page)
+ cursor = dbapi.db_aggregate(self.table, pipelines)
+ while (yield cursor.fetch_next):
+ data.append(self.format_data(cursor.next_object()))
if res_op is None:
res = {self.table: data}
else: