#21134: Documentation for transaction.atomic needs more explicit warning about catching DatabaseErrors -------------------------------------+------------------------------------- Reporter: RichardOfWard | Owner: aaugustin Type: | Status: closed Cleanup/optimization | Version: Component: Documentation | 1.6-beta-1 Severity: Normal | Resolution: fixed Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by akaariai): The committed documentation changes aren't about what I have been complaining about. I have said numerous times that *this is not about DatabaseErrors*. This is about any error that bubbles out of atomic(savepoint=False) block. The problem is this: {{{ r1 = Reporter.objects.create(first_name='foo', last_name='bar') with transaction.atomic(): r2 = Reporter(first_name='foo', last_name='bar2', id=r1.id) try: r2.save(force_insert=True) except IntegrityError: r2.save(force_update=True) self.assertEqual(Reporter.objects.get(pk=r1.pk).last_name, 'bar2') }}} The last assert fails. This is unexpected for anybody using a database where this pattern is allowed (as far as I know any db other than PostgreSQL). Note that there isn't any explicit use of atomic(savepoint=False) blocks. Also, the exception *does not need to be DatabaseError subclass at all*. -- Ticket URL: <https://code.djangoproject.com/ticket/21134#comment:3> 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.7d192d41b6009aa329b84bb54fbc2474%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.