开发者

Django Tests fail with InternalError: no such savepoint. DB: Postgres, passes on mysql

开发者 https://www.devze.com 2022-12-10 01:19 出处:网络
Interestingly it also works on the shell. [MY code which calls Model.objects.get_or_create(...)] File \"/usr/lib/python2.5/site-packages/django/db/models/manager.py\", line 123, in get_or_create

Interestingly it also works on the shell.

   [MY code which calls Model.objects.get_or_create(...)]
  File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 123, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 308, in get_or_create
    transaction.savepoint_rollback(sid)
  File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 199, in savepoint_rollback
    connection._savepoint_rollback(sid)
  File "/usr/lib/python2.5/site-packages/开发者_Python百科django/db/backends/__init__.py", line 67, in _savepoint_rollback
    self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
InternalError: no such savepoint


If you want to test code that uses transactions, you'll need to subclass TransactionTestCase instead of TestCase

for example:

from django.test import TransactionTestCase

class MyTests(TransactionTestCase):
    ...

It probably passes in MySql because you're using MyISAM tables which don't support transactions

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号