I don't think the subclass of TestCase need to use transaction.atomic. Why
can't you just remove the transaction.atomic?

Regards,

Aldian Fazrihady
http://aldianfazrihady.com

Pada tanggal Sel, 12 Mei 2020 04.02, Uri Kogan <urk...@gmail.com> menulis:

> Hello,
>
> I am using TestCase and trying to create an object during test.
> There is a log activated on MySQL server, so I see all the queries being
> executed there.
>
> This "transaction.atomic" sets a SAVEPOINT in the database thinking that
> the transaction is already started. The problem is that there is no
> "TRANSACTION START". So, when exiting "with transaction.atomic()" block the
> whole thing crashes with "SAVEPOINT xxx DOES NOT EXIST"
>
> The following states that TestCase "tests within two nested atomic()
> blocks", so it should execute "TRANSACTION START"
>
> https://docs.djangoproject.com/en/3.0/topics/testing/tools/#django.test.TestCase
>
>
> from django.contrib.auth.models import User
> from django.test import TestCase
>
>
> class FooTest(TestCase):
>     def test_bar(self):
>         with transaction.atomic():
>             user = User.objects.create_user(username="abc",
> password="pass")
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ecff11bd-9d35-4130-9d3a-0d48f70af73f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ecff11bd-9d35-4130-9d3a-0d48f70af73f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7EoAZi_aRZcppf1xZ6XLF4FGJULq3pL7pnoi33HainJa0JgQ%40mail.gmail.com.

Reply via email to