|
| 1 | +# Django Subatomic's features |
| 2 | + |
| 3 | +## Intentional transaction management |
| 4 | + |
| 5 | +... |
| 6 | + |
| 7 | +## No queries wasted on unused savepoints |
| 8 | + |
| 9 | +... |
| 10 | + |
| 11 | +## Fast, production-like tests |
| 12 | + |
| 13 | +Django tests are usually wrapped in a database transaction |
| 14 | +which is rolled back when the test completes. |
| 15 | +This means that after-commit callbacks would usually never be run. |
| 16 | + |
| 17 | +To simulate realistic production behaviour, |
| 18 | +Subatomic runs after-commit callbacks when we exit the |
| 19 | +outermost [`transaction`][django_subatomic.db.transaction] |
| 20 | +(or [`transaction_if_not_already`][django_subatomic.db.transaction_if_not_already]) context. |
| 21 | +This emulates how the application will behave when deployed |
| 22 | +and means that tests reproduce realistic application behaviour |
| 23 | +without resorting to other more costly or error-prone testing strategies. |
| 24 | + |
| 25 | +## No more accidental immediate "after-commit" callbacks |
| 26 | + |
| 27 | +Subatomic's [`run_after_commit`][django_subatomic.db.run_after_commit] will ensure that |
| 28 | +after-commit callbacks are only registered when a transaction is open. |
| 29 | +If no transaction is open, an error will be raised. |
| 30 | + |
| 31 | +This is in contrast to the default behaviour of Django's [`on_commit`][on_commit] function, |
| 32 | +where after-commit callbacks outside of transactions are executed immediately. |
| 33 | + |
| 34 | +We choose to disallow immediate execution because it can be misleading and hide bugs. |
| 35 | +In particular, it can hide the fact that a transaction is missing or on a different database, |
| 36 | +which can make code read as though a callback will be deferred when it won't be. |
| 37 | + |
| 38 | +## Progressive integration support |
| 39 | + |
| 40 | +The larger your project is, |
| 41 | +the more likely you are to benefit from |
| 42 | +the guardrails offered by Django Subatomic's strict features. |
| 43 | +Paradoxically, the larger your project is, |
| 44 | +the more difficult it may be to enable them all. |
| 45 | + |
| 46 | +Because integrating Django Subatomic all at once |
| 47 | +could be a daunting task for larger projects, |
| 48 | +we provide some [settings to ease the integration process](/reference/settings). |
| 49 | +They allow you to roll out strict behaviour on a per-test basis |
| 50 | +using Django's `override_settings`. |
| 51 | + |
| 52 | +[on_commit]: https://docs.djangoproject.com/en/stable/topics/db/transactions/#django.db.transaction.on_commit |
| 53 | +[override_settings]: https://docs.djangoproject.com/en/stable/topics/testing/tools/#django.test.override_settings |
| 54 | +[TransactionTestCase]: https://docs.djangoproject.com/en/stable/topics/testing/tools/#transactiontestcase |
0 commit comments