Skip to content

Commit 404ea64

Browse files
committed
Return early if transactions aren't required
The logic in this function is about to get bigger, and this early return saves us from repeating the same check on each if-block.
1 parent baff60d commit 404ea64

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • src/django_subatomic

src/django_subatomic/db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,13 @@ def _ensure_transaction_is_open(*, using: str) -> None:
450450
needs_transaction = getattr(
451451
settings, "SUBATOMIC_AFTER_COMMIT_NEEDS_TRANSACTION", True
452452
)
453+
if not needs_transaction:
454+
return
453455

454456
# Fail if a transaction is required, but none exists.
455457
# Ignore test-suite transactions when checking for a transaction.
456458
# See Note [After-commit callbacks require a transaction]
457-
if needs_transaction and not in_transaction(using=using):
459+
if not in_transaction(using=using):
458460
raise _MissingRequiredTransaction(database=using)
459461

460462

0 commit comments

Comments
 (0)