asgiref.local.Local
used to isolate changes performed in asyncio tasks in pre-3.7, and stopped doing so from 3.7+. This is likely an issue, since the point of asgiref.local.Local
compared to threading.local
ought to be to provide locals also for asyncio concurrency.
I created a complete reproducer in asgiref-test.py.gz
I tracked the issue to the way asgiref.local.Local sets values: if I read it correctly it does it in a way that it changes the dict in the previous context: it tries to do a get/update/set cycle, but it updates the mutable dict returned by get()
, so the side effect propagates to the state reachable before set
is called.
Indeed, chaging that line with storage_object = self._data.get({}).copy()
makes it behave how I would expect.