TransactionManagementError “You can't execute queries until the end of the 'atomic' block” while using signals, but only during Unit Testing

后端 未结 11 2077
有刺的猬
有刺的猬 2020-12-02 06:03

I am getting TransactionManagementError when trying to save a Django User model instance and in its post_save signal, I\'m saving some models that have the user as the forei

11条回答
  •  眼角桃花
    2020-12-02 06:37

    I have the same issue, but with transaction.atomic() and TransactionTestCase didn't work for me.

    python manage.py test -r instead of python manage.py test is ok for me, maybe the order of execution is crucial

    then i find a doc about Order in which tests are executed, It mentions which test will run first.

    So, i use TestCase for database interaction, unittest.TestCase for other simple test, it works now!

提交回复
热议问题