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

后端 未结 11 2071
有刺的猬
有刺的猬 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:29

    In my case it was caused but not calling super().tearDownClass()

    class TnsFileViewSetTestCase(APITestCase):
        @classmethod
        def tearDownClass(self):
            super().tearDownClass()    # without this line we will get TransactionManagementError
            for tnsfile in TnsFile.objects.all():
                tnsfile.file.delete()
    

提交回复
热议问题