From 1e1420d92b5f7da0428d6dc12d10d454c5ae5b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 14 May 2019 14:23:13 +0200 Subject: [PATCH] Fixed race condition in fetching task activities Since MongoDB stores timestamps with a resolution of a millisecond, it was possible for a task to be created and updated on the same timestamp, which could cause an impossible ordering of the activities (edit before creation). Sorting by ID instead of creation timestamp fixes this. --- attract/__init__.py | 2 +- attract/routes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/attract/__init__.py b/attract/__init__.py index 333cf09..fa2bdaa 100644 --- a/attract/__init__.py +++ b/attract/__init__.py @@ -218,7 +218,7 @@ class AttractExtension(PillarExtension): 'context_object': node_id}, ], }, - 'sort': [('_created', -1)], + 'sort': [('_id', 1)], # Sort by creation, _id is incremental. 'max_results': max_results, 'page': page, }, api=api) diff --git a/attract/routes.py b/attract/routes.py index 0af7833..2521694 100644 --- a/attract/routes.py +++ b/attract/routes.py @@ -51,7 +51,7 @@ def index(): 'where': { 'project': {'$in': list(id_to_proj.keys())}, }, - 'sort': [('_created', -1)], + 'sort': [('_id', 1)], # Sort by creation, _id is incremental. 'max_results': 20, }, api=api)