#21134: Documentation for transaction.atomic needs more explicit warning about catching DatabaseErrors -------------------------------------+------------------------------------- Reporter: RichardOfWard | Owner: aaugustin Type: | Status: new Cleanup/optimization | Version: Component: Documentation | 1.6-beta-1 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by aaugustin): This pull request prevents running queries in `atomic` blocks that are going to end with a rollback. Since `atomic` is a new API, this change looks like it's backwards compatible. Unfortunately, it isn't, because some features already take advantage of `atomic` internally. Specifically `django.test.TestCase` wraps each test in an `atomic` block. As a consequence, tests that ran queries after database errors will require modifications, even if the query is a rollback to a previous savepoint. That said: - If it's a test for transactional behavior, it should be in a `TransactionTestCase`. Quite obviously high-level and low-level APIs cannot be mixed arbitrarily. - If the savepoint is used to recover from a database error, it's much easier to recover with an `atomic` block. This is how I fixed the few tests that were broken by this change in Django's test suite. If we decide to go with this approach, I'll add this to the transactions docs or the release notes. -- Ticket URL: <https://code.djangoproject.com/ticket/21134#comment:6> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/071.da1acd6eb681a245b4b1bdc861cab3f5%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.