From bae25765a6b177a090c35be9953c03e30fcb3343 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 23 Sep 2021 15:21:43 +0500 Subject: [PATCH 1/6] fix: Added durable argument to transaction.atomic. It is implemented in django32. --- common/djangoapps/util/db.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index bb6e3332c1..3b8891311d 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -52,9 +52,10 @@ class OuterAtomic(transaction.Atomic): """ ALLOW_NESTED = False - def __init__(self, using, savepoint, name=None): + def __init__(self, using, savepoint, durable=False, name=None): self.name = name - super().__init__(using, savepoint) + self.durable = durable + super().__init__(using, savepoint, durable) def __enter__(self): @@ -84,7 +85,7 @@ class OuterAtomic(transaction.Atomic): super().__enter__() -def outer_atomic(using=None, savepoint=True, name=None): +def outer_atomic(using=None, savepoint=True, name=None, durable=False): """ A variant of Django's atomic() which cannot be nested inside another atomic. @@ -120,10 +121,10 @@ def outer_atomic(using=None, savepoint=True, name=None): TransactionManagementError: if already inside an atomic block. """ if callable(using): - return OuterAtomic(DEFAULT_DB_ALIAS, savepoint)(using) + return OuterAtomic(DEFAULT_DB_ALIAS, savepoint, durable)(using) # Decorator: @outer_atomic(...) or context manager: with outer_atomic(...): ... else: - return OuterAtomic(using, savepoint, name) + return OuterAtomic(using, savepoint, name, durable) def generate_int_id(minimum=0, maximum=MYSQL_MAX_INT, used_ids=None): From cb0a56fb0de69cd9e59c7f1c802b298e44a3f01a Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 23 Sep 2021 15:24:43 +0500 Subject: [PATCH 2/6] fix: Added durable argument to transaction.atomic. It is implemented in django32. --- common/djangoapps/util/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index 3b8891311d..41d0763623 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -52,7 +52,7 @@ class OuterAtomic(transaction.Atomic): """ ALLOW_NESTED = False - def __init__(self, using, savepoint, durable=False, name=None): + def __init__(self, using, savepoint, name=None, durable=False,): self.name = name self.durable = durable super().__init__(using, savepoint, durable) From 5772b89f540527bc4286ea6b040b543ef1f21931 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 23 Sep 2021 15:38:58 +0500 Subject: [PATCH 3/6] fix: Added durable argument to transaction.atomic. It is implemented in django32. --- common/djangoapps/util/db.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index 41d0763623..748b682f33 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -8,7 +8,7 @@ import random # TransactionManagementError used below actually *does* derive from the standard "Exception" class. # lint-amnesty, pylint: disable=bad-option-value, nonstandard-exception from contextlib import contextmanager - +import django from django.db import DEFAULT_DB_ALIAS, transaction # lint-amnesty, pylint: disable=unused-import from openedx.core.lib.cache_utils import get_cache @@ -52,10 +52,13 @@ class OuterAtomic(transaction.Atomic): """ ALLOW_NESTED = False - def __init__(self, using, savepoint, name=None, durable=False,): + def __init__(self, using, savepoint, name=None, durable=False): self.name = name self.durable = durable - super().__init__(using, savepoint, durable) + if django.VERSION >= (3, 1): + super().__init__(using, savepoint, durable) + else: + super().__init__(using, savepoint) def __enter__(self): From 129a27314f316cb2665de6e0d07d90ffc59b148e Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 23 Sep 2021 17:15:08 +0500 Subject: [PATCH 4/6] fix: Added durable argument to transaction.atomic. It is implemented in django32. --- common/djangoapps/util/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index 748b682f33..1b56fbad79 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -56,7 +56,7 @@ class OuterAtomic(transaction.Atomic): self.name = name self.durable = durable if django.VERSION >= (3, 1): - super().__init__(using, savepoint, durable) + super().__init__(using, savepoint, durable) # pylint: disable=too-many-arguments else: super().__init__(using, savepoint) From 70e594e63fdd9c455e4615dfdd7ad7ddf22bedea Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 23 Sep 2021 18:00:42 +0500 Subject: [PATCH 5/6] fix: Added durable argument to transaction.atomic. It is implemented in django32. --- common/djangoapps/util/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index 1b56fbad79..d07a040a4d 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -56,7 +56,7 @@ class OuterAtomic(transaction.Atomic): self.name = name self.durable = durable if django.VERSION >= (3, 1): - super().__init__(using, savepoint, durable) # pylint: disable=too-many-arguments + super().__init__(using, savepoint, durable) # pylint: disable=too-many-function-args else: super().__init__(using, savepoint) From ca8f96439917be889faba7628ba06ce6fa88b46a Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 23 Sep 2021 20:01:08 +0500 Subject: [PATCH 6/6] Update db.py --- common/djangoapps/util/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index d07a040a4d..81ffa8b25c 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -55,7 +55,7 @@ class OuterAtomic(transaction.Atomic): def __init__(self, using, savepoint, name=None, durable=False): self.name = name self.durable = durable - if django.VERSION >= (3, 1): + if django.VERSION >= (3, 2): super().__init__(using, savepoint, durable) # pylint: disable=too-many-function-args else: super().__init__(using, savepoint)