Skip to content

asgiref.local.Local fails to isolate changes between asyncio tasks #473

@spanezz

Description

@spanezz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions