Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Exceptions raised through `transaction_if_not_already`
when it was called from inside an existing transaction
will no longer invalidate the outer transaction's context.
- Remove `attrs` dependency to improve import time.

### Added
- Added MariaDB and SQLite to the test matrix.
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ readme = "README.md"

requires-python = ">=3.12"
dependencies = [
"attrs",
"django",
]

Expand Down
26 changes: 20 additions & 6 deletions src/django_subatomic/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import functools
from typing import TYPE_CHECKING, overload

import attrs
from django import db as django_db
from django.conf import settings
from django.db import transaction as django_transaction
Expand Down Expand Up @@ -302,7 +301,6 @@ def _execute_on_commit_callbacks_in_tests(using: str | None = None) -> Generator
# we need to permit the test-suite's transaction.


@attrs.frozen
class _MissingRequiredTransaction(Exception):
"""
Raised by `transaction_required` when we're not in a transaction.
Expand All @@ -327,8 +325,11 @@ class _MissingRequiredTransaction(Exception):

database: str

def __init__(self, database: str) -> None:
super().__init__()
self.database = database


@attrs.frozen
class _AmbiguousAfterCommitTestBehaviour(Exception):
"""
Raised in tests when it's unclear if after-commit callbacks should be run.
Expand Down Expand Up @@ -358,8 +359,11 @@ class _AmbiguousAfterCommitTestBehaviour(Exception):

database: str

def __init__(self, database: str) -> None:
super().__init__()
self.database = database


@attrs.frozen
class _UnexpectedOpenTransaction(Exception):
"""
Raised when calling a `durable` function with an open transaction.
Expand All @@ -376,8 +380,11 @@ class _UnexpectedOpenTransaction(Exception):

open_dbs: frozenset[str]

def __init__(self, open_dbs: frozenset[str]) -> None:
super().__init__()
self.open_dbs = open_dbs


@attrs.frozen
class _UnexpectedDanglingTransaction(Exception):
"""
Raised when a `durable` function exits with a transaction open.
Expand All @@ -390,8 +397,11 @@ class _UnexpectedDanglingTransaction(Exception):

open_dbs: frozenset[str]

def __init__(self, open_dbs: frozenset[str]) -> None:
super().__init__()
self.open_dbs = open_dbs


@attrs.frozen
class _UnhandledCallbacks(Exception):
"""
Raised in tests when unhandled callbacks are found before opening a transaction.
Expand All @@ -404,6 +414,10 @@ class _UnhandledCallbacks(Exception):

callbacks: tuple[Callable[[], object], ...]

def __init__(self, callbacks: tuple[Callable[[], object], ...]) -> None:
super().__init__()
self.callbacks = callbacks


# Note [After-commit callbacks require a transaction]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions src/django_subatomic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import contextlib
from typing import TYPE_CHECKING

import attrs
from django.conf import settings
from django.db import transaction

Expand All @@ -16,7 +15,6 @@
]


@attrs.frozen
class _UnhandledCallbacks(Exception):
"""
Raised in tests when unhandled callbacks are found before calling `part_of_a_transaction`.
Expand All @@ -29,6 +27,10 @@ class _UnhandledCallbacks(Exception):

callbacks: tuple[Callable[[], object], ...]

def __init__(self, callbacks: tuple[Callable[[], object], ...]) -> None:
super().__init__()
self.callbacks = callbacks


class _OnlyForUseInDjangoTestTransaction(Exception):
"""
Expand Down
Loading