Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_prepare_connection not called on write connections #1564

Closed
simonw opened this issue Dec 17, 2021 · 1 comment
Closed

_prepare_connection not called on write connections #1564

simonw opened this issue Dec 17, 2021 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Dec 17, 2021

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

@simonw simonw added the bug label Dec 17, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 18, 2021

Made this change while working on this issue:

I'm going to write a test for this that uses that sleep() SQL function from c35b84a.

@simonw simonw closed this as completed in 83bacfa Dec 18, 2021
simonw added a commit that referenced this issue Dec 19, 2021
@simonw simonw added this to the Datasette 0.60 milestone Jan 13, 2022
simonw added a commit that referenced this issue Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant