diff --git a/data/queue.py b/data/queue.py index 60632f5b1..d40df3335 100644 --- a/data/queue.py +++ b/data/queue.py @@ -120,16 +120,21 @@ class WorkQueue(object): name_match_query = self._name_match_query() running = self._running_jobs(now, name_match_query) - avail = self._available_jobs_not_running(now, name_match_query, running) + avail = self._available_jobs_not_running(now, name_match_query, running).alias('avail') item = None try: - db_item_candidate = avail.order_by(QueueItem.id).get() + db_item_candidate_id = (QueueItem + .select(avail.c.id) + .from_(avail) + .order_by(avail.c.id) + .tuples() + .get())[0] with self._transaction_factory(db): still_available_query = (db_for_update(self ._available_jobs(now, name_match_query) - .where(QueueItem.id == db_item_candidate.id))) + .where(QueueItem.id == db_item_candidate_id))) db_item = still_available_query.get() db_item.available = False