-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
render_cell() hook should support returning an awaitable #1425
Comments
I can do this with the Lines 864 to 873 in a21853c
|
Still one test failure:
The weird thing about this one is that I can't replicate it on my laptop - but it happens in CI every time, including when I shell in and try to run that single test. |
My hunch is that the "skip this Could that be because Pluggy handles the "do the next if This would suggest that all of the Still don't see why it would pass on my laptop but fail in CI though. |
Good news: datasette/datasette/hookspecs.py Lines 62 to 64 in f3c9edb
|
Here's the code in if hook_impl.hookwrapper:
try:
gen = hook_impl.function(*args)
next(gen) # first yield
teardowns.append(gen)
except StopIteration:
_raise_wrapfail(gen, "did not yield")
else:
res = hook_impl.function(*args)
if res is not None:
results.append(res)
if firstresult: # halt further impl calls
break |
I could extract that code out and write my own function which implements the equivalent of calling That's pretty nasty. Could I instead call the plugin hook normally, but then have additional logic which says "if I await it and it returns I could remove the |
I'm trying the version where I remove |
Demo: https://latest.datasette.io/fixtures/simple_primary_key shows datasette/tests/plugins/my_plugin.py Lines 98 to 122 in a390bdf
|
I used this to build a new plugin: https://github.com/simonw/datasette-query-links |
I believe this also provides a workaround for the problem I face in #1300. Now I should be able to get table PKs and generate a row URL. I'll test this out and report my findings. from datasette.utils import path_from_row_pks
pks = await db.primary_keys(table)
url = self.ds.urls.row_blob(
database,
table,
path_from_row_pks(row, pks, not pks),
column,
) |
Many of the plugin hooks can return an awaitable - e.g. https://docs.datasette.io/en/stable/plugin_hooks.html#plugin-hook-extra-template-vars - but
render_cell()
doesn't support this.I recently found myself wanting to execute an additional SQL query from that hook, but it wasn't possible to do that since I couldn't use
await
.The text was updated successfully, but these errors were encountered: