From 2e2e57d231e97dbd0f1a57330bd5111e551bfc9e Mon Sep 17 00:00:00 2001 From: Kara Engelhardt Date: Tue, 24 Mar 2026 13:43:36 +0100 Subject: [PATCH] Fix typo in test detection, improve check A non-empty string is truthy, making the the for-loop useless, as the first item in inspect.stack() is always the for-loop itself, which then lead to the function returning immediately. This commit * fixes this typo * changes the loop to ignore the first element of instpect.stack() (which is the loop itself) * ignores django-internal code This should create something similar to what I suspect the code was intended to do originally. --- src/pretix/base/models/_transactions.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pretix/base/models/_transactions.py b/src/pretix/base/models/_transactions.py index 1aaf2919bf..8ee37e036b 100644 --- a/src/pretix/base/models/_transactions.py +++ b/src/pretix/base/models/_transactions.py @@ -29,7 +29,9 @@ import inspect import logging import os import threading +from pathlib import Path +import django from django.conf import settings from django.db import transaction @@ -74,10 +76,14 @@ def _transactions_mark_order_dirty(order_id, using=None): if "PYTEST_CURRENT_TEST" in os.environ: # We don't care about Order.objects.create() calls in test code so let's try to figure out if this is test code # or not. - for frame in inspect.stack(): - if 'pretix/base/models/orders' in frame.filename: + for frame in inspect.stack()[1:]: + if ( + 'pretix/base/models/orders' in frame.filename + or Path(frame.filename).is_relative_to(Path(django.__file__).parent) + ): + # Ignore model- and django-internal code continue - elif 'test_' in frame.filename or 'conftest.py in frame.filename': + elif 'test_' in frame.filename or 'conftest.py' in frame.filename: return elif 'pretix/' in frame.filename or 'pretix_' in frame.filename: # This went through non-test code, let's consider it non-test