From 1c5806a98e965d91f7da6352a6b5d05b5e9d7fec Mon Sep 17 00:00:00 2001 From: Sven Eberth Date: Fri, 14 May 2021 17:18:55 +0200 Subject: [PATCH] This avoid infinity queries due to a wrong new cursor This is a workaround for a bug in the datastore-emulator, see https://github.com/googleapis/google-cloud-datastore/issues/130 https://github.com/googleapis/google-cloud-node/issues/2846 --- core/db.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/db.py b/core/db.py index 0d288bdfd..ed7520228 100644 --- a/core/db.py +++ b/core/db.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import annotations + +import os + from viur.core.config import conf from viur.core import utils import logging @@ -660,7 +663,10 @@ def _runSingleFilterQuery(self, query, limit): qry.order = [x[0] if x[1] == SortOrder.Ascending else "-" + x[0] for x in query.orders] qryRes = qry.fetch(limit=limit, start_cursor=query.startCursor, end_cursor=query.endCursor) res = next(qryRes.pages) - query.currentCursor = qryRes.next_page_token + if os.getenv("DATASTORE_EMULATOR_HOST"): + query.currentCursor = qryRes.next_page_token if query.startCursor != qryRes.next_page_token else None + else: + query.currentCursor = qryRes.next_page_token return res def _mergeMultiQueryResults(self, inputRes: List[List[Entity]]) -> List[Entity]: