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

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

    Since @mkoistinen never made his comment, an answer, I'll post his suggestion so people won't have to dig through comments.

    consider just declaring your test class as a TransactionTestCase rather than just TestCase.

    From the Django docs: A TransactionTestCase may call commit and rollback and observe the effects of these calls on the database.

提交回复
热议问题