Skip to content

Fix bug where cached threadlocal identifiers cause database replacement not to work #2465

@simonw

Description

@simonw

This issue in a plugin:

Was caused by this code, which means connections stick around even when a database should have been replaced:

https://github.com/simonw/datasette/blob/53a3b3c80e64fa3733196b1478e4a4fc60b08fd4/datasette/database.py#L27C1-L27C32

def in_thread():
conn = getattr(connections, self.name, None)
if not conn:
conn = self.connect()
self.ds._prepare_connection(conn, self.name)
setattr(connections, self.name, conn)
return fn(conn)

The problem is that if you have a database with name dogs and you use remove_database() and then add_database() to try and replace it with a new database of the same name the existing threads continue to reference an old connection to that database.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions