From 00c78a2ed3bbaf2b508d8ae3978fe2ae84aa7b62 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 6 Oct 2025 10:12:33 +0200 Subject: [PATCH] Do not run during tests --- src/pretix/helpers/database.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pretix/helpers/database.py b/src/pretix/helpers/database.py index 1ade96ddd..4e537ff1c 100644 --- a/src/pretix/helpers/database.py +++ b/src/pretix/helpers/database.py @@ -80,15 +80,19 @@ def repeatable_reads_transaction(): **You should only make read-only queries during this transaction and not rely on quota calculations.** """ + is_under_test = 'tests.testdummy' in settings.INSTALLED_APPS try: - with transaction.atomic(durable=True): - with connection.cursor() as cursor: - if 'postgresql' in settings.DATABASES['default']['ENGINE']: - cursor.execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;') - elif 'sqlite' in settings.DATABASES['default']['ENGINE']: - pass # noop - else: - raise ImproperlyConfigured("Cannot set transaction isolation mode on this database backend") + with transaction.atomic(durable=not is_under_test): + if not is_under_test: + # We're not running this in tests, where we can basically not use this since the test runner does its + # own transaction logic for efficiency + with connection.cursor() as cursor: + if 'postgresql' in settings.DATABASES['default']['ENGINE']: + cursor.execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;') + elif 'sqlite' in settings.DATABASES['default']['ENGINE']: + pass # noop + else: + raise ImproperlyConfigured("Cannot set transaction isolation mode on this database backend") connection.tx_in_repeatable_read = True yield