Skip to content

_prepare_connection not called on write connections #1564

@simonw

Description

@simonw

I was trying to initalize SpatiaLite in a write connection:

>>> from datasette.app import Datasette
>>> ds = Datasette(memory=True, files=[], sqlite_extensions=["spatialite"])
>>> db = ds.add_memory_database('geo')
>>> await db.execute_write("select InitSpatialMetadata(1)")
UUID('3f143baa-4e3d-5842-a36f-4fa2f683b72f')
no such function: InitSpatialMetadata

It looks like the code that loads additional modules only works on read-only connections, not on write connections:

async def execute_fn(self, fn):
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)

Compared to:

def _execute_writes(self):
# Infinite looping thread that protects the single write connection
# to this database
conn_exception = None
conn = None
try:
conn = self.connect(write=True)
except Exception as e:
conn_exception = e

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions