datasette icon indicating copy to clipboard operation
datasette copied to clipboard

Clicking 'Run SQL' from extneded query.html page results in URL not found error

Open hcarter333 opened this issue 11 months ago • 9 comments

Version: 1.0a19

I see the following initial query form button, (the point to note here is that we're not in the query.html extension yet.)

Image

on the database's home page http://192.168.0.203/sam_datasette/rm_toucans_slice

Image

The initial query page's form looks like this

<html>
<body>
<!--StartFragment-->
<form class="sql core" action="/sam_datasette/rm_toucans_slice/-/query" method="get">
--
  | <h3>Custom SQL query</h3>
  | <p><textarea id="sql-editor" name="sql">select * from rm_rnb_history_pres</textarea></p>
  | <p>
  | <button id="sql-format" type="button" hidden>Format SQL</button>
  | <input type="submit" value="Run SQL">
  | </p>
  | </form>

<!--EndFragment-->
</body>
</html>

After running the query, the form looks like

Image

The query page form after the query has been run and landed in an extended query.html looks like this

<form class="sql core" action="/sam_datasette/rm_toucans_slice" method="get">
--
  | <h3>Custom SQL query returning 50 rows
  | <span class="show-hide-sql">(<a href="/sam_datasette/rm_toucans_slice/-/query?sql=++++++select%0D%0A++rowid%2C%0D%0A++id%2C%0D%0A++tx_lng%2C%0D%0A++tx_lat%2C%0D%0A++rx_lng%2C%0D%0A++rx_lat%2C%0D%0A++timestamp%2C%0D%0A++strftime%28%27%25Y%25m%25d%27%2C+timestamp%29+as+date%2C%0D%0A++strftime%28%27%25H%25M%27%2C+timestamp%29+as+time%2C%0D%0A++midpoint_lat%28tx_lat%2C+tx_lng%2C+rx_lat%2C+rx_lng%29+as+ap_lat%2C%0D%0A++midpoint_lng%28tx_lat%2C+tx_lng%2C+rx_lat%2C+rx_lng%29+as+ap_lng%2C++%0D%0A++haversine%28tx_lat%2C+tx_lng%2C+rx_lat%2C+rx_lng%29+as+length%2C%0D%0A++dB%2C%0D%0A++frequency%2C%0D%0A++Spotter%2C%0D%0A++Country%2C%0D%0A++State%2C%0D%0A++County%2C%0D%0A++City%2C%0D%0A++QSL_Sent%2C%0D%0A++QSL_Rx%2C%0D%0A++QSL_link%2C%0D%0A++QSL_rx_link%2C%0D%0A++tx_rst%2C%0D%0A++park%2C%0D%0A++p2p_s2%2C%0D%0A++call%2C%0D%0A++skcc%2C%0D%0A++naqcc%2C%0D%0A++f2m%2C%0D%0A++launchangle%2C%0D%0A++%2722%27+as+elev_tx%0D%0Afrom%0D%0A++rm_rnb_history_pres%0D%0Awhere+%0D%0A++dB+%3E+100%0D%0A++and+timestamp+%3E+%272025-04-26T00%3A25%3A00%27%0D%0A++and+timestamp+%3C+%272025-04-27T01%3A55%3A00%27%0D%0Aorder+by%0D%0A++timestamp%0D%0A&amp;_hide_sql=1">hide</a>)</span>
  | </h3>
  |  
  |  
  |  
  | <p><textarea id="sql-editor" name="sql" style="height: 44em"
  | >      select
  | rowid,
  | id,
  | tx_lng,
  |  

Notice that the form action has changed and no longer contains the breadcrum. When the 'Run SQL' button is clicked again with no other changes, the page isn't found

Image

Also notice that the not found address: http://192.168.0.203/rm_toucans_slice/-/query?sql=+

no longer contains sam_datasette, while the previous address did: http://192.168.0.203/sam_datasette/rm_toucans_slice/-/query?sql=+++

sam_datasette being stripped is causing the URL not found error

hcarter333 avatar May 10 '25 14:05 hcarter333

The first question: Is this caused by the template that extends query.html. I'm moving it to the side by renaming it query_mytest.html.

I am no longer using the customized query.html, but still getting the same error. The normal queqry page looks like

Image

While the customized page looks like

Image

The same error occurs for both pages.

hcarter333 avatar May 10 '25 15:05 hcarter333

The next question is if this is caused by #2454 I'm rolling my install back to 1.0a16

That did not fix the issue. Still seeing the same error and cause.

Image

hcarter333 avatar May 10 '25 15:05 hcarter333

Changing to localhost does fix the issue http://127.0.0.1:8001/rm_toucans_slice/-/query?sql=++++++select%0D%0A+

but means I can't run with other boxes on the network.

The command line is python -m datasette glotec_slice.db rm_toucans_slice.db --plugins-dir=plugins --template-dir plugins/templates --root --static assets:static-files/ --setting sql_time_limit_ms 1700000 --setting max_returned_rows 100000 --cors --crossdb --setting base_url /sam_datasette/ -p 8001

hcarter333 avatar May 10 '25 15:05 hcarter333

Thanks, definitely a bug.

simonw avatar May 10 '25 15:05 simonw

Possible to recreate this on https://latest.datasette.io/ ?

simonw avatar May 10 '25 15:05 simonw

Note: both versions of ProxyPass mentioned below resulted in the same issue above on the 1.0+ versions tried above.

This might be a local issue. On version 0.65.1, (where the above issue is not happening), when I configure httpd.conf as per the instructions:

ServerName 192.168.0.203:80
ProxyPass /sam_datasette/ http://127.0.0.1:8001/sam_datasette/ connectiontimeout=300 timeout=300
ProxyPreserveHost On

My plugins all gain a second sam_datasette as in: http://192.168.0.203/sam_datasette/sam_datasette/rm_toucans_slice.czml?sql=%0A%20%20%20%20%20%20select%0A%20%20rowid%2C%0A%20%20id%2C%0.....

When I modify those instructions and use

ServerName 192.168.0.203:80
ProxyPass /sam_datasette/ http://127.0.0.1:8001/ connectiontimeout=300 timeout=300
ProxyPreserveHost On

this no longer occurs and the plugin points at http://192.168.0.203/sam_datasette/rm_toucans_slice.czml?sql=++++++se...

Consequently, I'm not following the correct httpd.conf instructions.

hcarter333 avatar May 10 '25 15:05 hcarter333

I'm don't see the same issue on

https://latest.datasette.io/

I've tried with the tables that are already in that database and don't see the issue. Should I, (and can I), try with my tables or template on that database?

hcarter333 avatar May 10 '25 19:05 hcarter333

Current state for the different versions. Yes/no refer to whether or not the action succeeded.

         
Version table page "Run SQL" refresh Query page 'Run SQL' plugin ProxyPass
1.0a16 yes yes No. URL not found yes Makeshift ProxyPass
1.0a16 yes yes No. URL not found yes documented ProxyPass

On the pre-1.0 version, we get

         
Version table page "Run SQL" refresh Query page 'Run SQL' plugin ProxyPass
0.65.1 yes yes yes no: doubles up sam_datasette in the URL as in http://192.168.0.203/sam_datasette//sam_datasette documented ProxyPass
0.65.1 yes yes yes yes MakeshiftProxyPass

hcarter333 avatar May 10 '25 19:05 hcarter333

On 1.0a16, remote plugin calls of the form: rm_toucans_slice.czml?sql=select...

no longer work. Instead, they have to have the form: rm_toucans_slice/-/query.czml?sql=select...

hcarter333 avatar May 10 '25 20:05 hcarter333