Database errors in Django when using threading

前端 未结 3 1317
小蘑菇
小蘑菇 2021-02-07 11:11

I am working in a Django web application which needs to query a PostgreSQL database. When implementing concurrency using Python threading interface, I am getting DoesNotEx

3条回答
  •  萌比男神i
    2021-02-07 12:07

    Becomes more clear from this part of the documentation

    class LiveServerTestCase(TransactionTestCase):
        """
        ...
        Note that it inherits from TransactionTestCase instead of TestCase because
        the threads do not share the same transactions (unless if using in-memory
        sqlite) and each thread needs to commit all their transactions so that the
        other thread can see the changes.
        """
    

    Now, the transaction has not been committed inside a TestCase, hence the changes are not visible to the other thread.

提交回复
热议问题