-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
v0.54 500 error from sql query in custom template; code worked in v0.53; found a workaround #3
Comments
Good catch on the workaround here. The root problem is that Is this a bug? I think it is - because the documented behaviour on https://docs.datasette.io/en/stable/internals.html#get-database-name is this:
Since the new behaviour differs from what was in the documentation I'm going to treat this as a bug and fix it. |
Oh weird, the code is supposed to be doing that already: https://github.com/simonw/datasette/blob/382e9ecd1d429102417b17a1bd75f066cb904e24/datasette/app.py#L367-L371 Here's the associated test: https://github.com/simonw/datasette/blob/dde3c500c73ace33529672f7d862b76753d309cc/tests/test_internals_datasette.py#L21-L24 |
I'm pretty sure this is a bug in |
Running
|
Here's why: datasette-template-sql/datasette_template_sql/__init__.py Lines 6 to 8 in c1a4a50
The |
Fix is now deployed to https://www.niche-museums.com/ - on my laptop it exhibited the 500 error with |
Just installed Many thanks! |
v0.54 500 error in sql query template; code worked in v0.53; found a workaround
schema:
CREATE TABLE "talks" ("talk" TEXT,"series" INTEGER, "talkdate" TEXT)
CREATE TABLE "series" ("id" INTEGER PRIMARY KEY, "series" TEXT, talks_list TEXT default '', website TEXT default '');
Live example of correctly rendered template in v.053: https://cosmotalks-cy6xkkbezq-uw.a.run.app/cosmotalks/talks/1
Description of problem: I needed 'sql select' code in a custom row-mydatabase-mytable.html template to lookup the series name for a foreign key integer value in the talks table. So
metadata.json
specifies thedatasette-template-sql
plugin.The code below worked perfectly in v0.53 (just the relevant sql statement part is shown; full code is here):
In v0.54, that code resulted in a 500 error with a 'no such table series' message. A second query in that template also did not work but the above is fully illustrative of the problem.
All templates were up-to-date along with datasette v0.54.
Workaround: After fiddling around with trying different things, what worked was the syntax from Querying a different database from the datasette-template-sql github repo to add the database name to the sql statement:
{% set sname = sql("select series from series where id = ?", [row.series], database="cosmotalks") %}
Though this was found to work, it should not be necessary to add
database="cosmotalks"
since per thedatasette-template-sql
README, it's only needed when querying a different database, but here it's a table within the same database.The text was updated successfully, but these errors were encountered: