#32409: TestCase async tests are not transaction-aware
-------------------------------------+-------------------------------------
Reporter: David | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: TestCase, async, | Triage Stage: Accepted
transaction |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David):
Using debugger I noticed this behaviour:
{{{
TestCase
|
| async_to_sync-> Thread (test)
|--------------------|
| |
| | (database_)sync_to_async ->Thread (ORM)
| |--------------------------------|
}}}
Since DB connection (along with savepoint/transaction references) resides
in the main thread it is hidden from re-synced code.
This behaviour could be fine if there is not any open transaction, since
every thread can hit the database independently. However, like in this
case, when the main thread opens a transaction this info is not trasmitted
through async-thread-chain thus resulting in reading a "wrong" state from
the database.
It could be addressed by making `async_to_sync` and `sync_to_async`
transaction-aware. I do not know if this can be achieved without an async-
ready database client.
--
Ticket URL: <https://code.djangoproject.com/ticket/32409#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.547f54c73ae7e83fa5ab822b6338ed9d%40djangoproject.com.