From 8b0c3163928566dd31fc6a9b49ae18d6127fc7bf Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 13 Jan 2022 23:06:29 +0100 Subject: [PATCH 1/2] utils: augment default retries in safe_get_or_create (#60645) --- src/authentic2/utils/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/authentic2/utils/models.py b/src/authentic2/utils/models.py index 131c3a23..6ab1e6e7 100644 --- a/src/authentic2/utils/models.py +++ b/src/authentic2/utils/models.py @@ -27,21 +27,21 @@ def poisson_random(frequency): return -math.log(1.0 - random.random()) / frequency -SAFE_GET_OR_CREATE_RETRIES = 3 +SAFE_GET_OR_CREATE_RETRIES = 100 class ConcurrencyError(Exception): pass -def safe_get_or_create(model, defaults=None, **kwargs): +def safe_get_or_create(model, defaults=None, retries=None, **kwargs): assert ( getattr(settings, 'TESTING', False) or not connection.in_atomic_block ), 'safe_get_or_create cannot be used in inside a transaction' defaults = defaults or {} exception = None - for dummy in range(SAFE_GET_OR_CREATE_RETRIES): + for dummy in range(retries or SAFE_GET_OR_CREATE_RETRIES): try: instance, created = model.objects.get_or_create(defaults=defaults, **kwargs) except model.MultipleObjectsReturned as e: -- 2.34.1