From 85f546a3a666909cf1a3b96471398a71f9771afd Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 23 Jul 2020 17:48:56 +0200 Subject: [PATCH] Ignore deadlock when writing quota caches --- src/pretix/base/services/quotas.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pretix/base/services/quotas.py b/src/pretix/base/services/quotas.py index a13d6af6a..91fd45cb7 100644 --- a/src/pretix/base/services/quotas.py +++ b/src/pretix/base/services/quotas.py @@ -3,7 +3,7 @@ from collections import Counter, defaultdict from datetime import timedelta from django.conf import settings -from django.db import models +from django.db import OperationalError, models from django.db.models import ( Case, Count, F, Func, Max, OuterRef, Q, Subquery, Sum, Value, When, ) @@ -103,7 +103,12 @@ class QuotaAvailability: self.results[q] = resp self._close(quotas) - self._write_cache(quotas, now_dt) + try: + self._write_cache(quotas, now_dt) + except OperationalError as e: + # Ignore deadlocks when multiple threads try to write to the cache + if 'deadlock' not in str(e).lower(): + raise e def _write_cache(self, quotas, now_dt): events = {q.event for q in quotas}