Code Monkey home page Code Monkey logo

Comments (18)

simonw avatar simonw commented on June 11, 2024

Well this is a fascinating bug! I've never seen it before, and I can't think of anything obvious that would cause it. I will dig in and see if I can replicate it.

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

Only current workaround I can suggest is trying Heroku or Cloud Run instead, but that's deeply unsatisfying.

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

CSV is affected by this too: https://thesession.vercel.app/thesession.csv?sql=select%20*%20from%20tunes%20where%20name%20like%20%22%wise%20maid%%22

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

... but the .json and .csv links on the table page at https://thesession.vercel.app/thesession/tunes behave correctly - so this bug only affects arbitrary SQL queries.

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

It's the % characters.

https://thesession.vercel.app/thesession.json?sql=select+*+from+tunes+where+name+like+%3Asearch%0D%0A&search=Wise+Maid%2C+The returns results correctly

So does https://thesession.vercel.app/thesession.json?sql=select%20*%20from%20tunes%20where%20name%20like%20:search&search=%Wise%20Maid,%20The%

This does NOT work: https://thesession.vercel.app/thesession.json?sql=select%20*%20from%20tunes%20where%20name%20like%20:search&search=%wise%20maid%

But this does: https://thesession.vercel.app/thesession.json?sql=select%20*%20from%20tunes%20where%20name%20like%20:search&search=%25wise%20maid%25

So in some circumstances a % that is not correctly URL-encoded works - but in other circumstances it does not and must be encoded as a %25.

from datasette-publish-vercel.

adactio avatar adactio commented on June 11, 2024

By Jove, I think you've cracked it!

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

The JSON from https://thesession.vercel.app/thesession.json?sql=select%20*%20from%20tunes%20where%20name%20like%20:search&search=%wise%20maid% has another clue:

{
  "ok": true,
  "query": {
    "sql": "select * from tunes where name like :search",
    "params": {
      "search": "wise maid"
    }
  },
  "error": null,
  "private": false,
  "allow_execute_sql": true,
  "query_ms": 18.020902999978716
}

Note that the "search" parameter is shown as "wise maid" without those % wildcards. In https://thesession.vercel.app/thesession.json?sql=select%20*%20from%20tunes%20where%20name%20like%20:search&search=%25wise%20maid%25 (the same thing but with % in the URL encoded as %25 it comes back as "%wise maid%".

I think there may be two bugs here.

Firstly, I suspect Vercel have a weird bug where under certain circumstances raw % in a query string fail to be passed through to the underlying application.

But... Datasette itself shouldn't be generating links to pages where the links have a % rather than a %25 in them.

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

Confirmed: https://thesession.vercel.app/thesession?sql=select+*+from+tunes+where+name+like+%22%25wise+maid%25%22%0D%0A is a page where the URL correctly encoded % as %25 - but then in the HTML on that page that links to the CSV and JSON versions we get this:

<p class="export-links">This data as
  <a href="/thesession.json?sql=select * from tunes where name like &#34;%wise maid%&#34;
">json</a>,
  <a href="/thesession.csv?sql=select * from tunes where name like &#34;%wise maid%&#34;
&amp;_size=max">CSV</a>
</p>

Those CSV and JSON links are incorrect.

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

Here's evidence of some Vercel weirdness - take a look at the 'query_string': output in these examples:

from datasette-publish-vercel.

abalter avatar abalter commented on June 11, 2024

Thanks so much for working on this!

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

@adactio I am finding this impossible to replicate on my own deployments to Vercel. Could you do me a favour and add --install datasette-debug-asgi to your datasette publish vercel command?

Doing so will add this page: https://til.simonwillison.net/-/asgi-scope to your thesession.vercel.app deployment which could help me figure out what's going on.

The big mystery: https://thesession.vercel.app/thesession?sql=select+*+from+tunes+where+name+like+%22%25a%25%22%0D%0A exhibits the bug (your Vercel deployment) - but the equivalent query https://til.simonwillison.net/fixtures?sql=select+*+from+searchable+where+text1+like+%22%25a%25%22%0D%0A against my Vercel deployment does NOT - if you view source on that page the .csv and .json links are correctly URL-escaped.

from datasette-publish-vercel.

adactio avatar adactio commented on June 11, 2024

Could you do me a favour and add --install datasette-debug-asgi to your datasette publish vercel command?

Done!

https://thesession.vercel.app/-/asgi-scope

from datasette-publish-vercel.

styfle avatar styfle commented on June 11, 2024

@now/python is deprecated, please use @vercel/python instead

If you're using Zero Config then this will happen automatically (rename source to /api/my-function.py, no config needed)

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

We're using @vercel/python already:

open("vercel.json", "w").write(
json.dumps(
{
"name": project,
"version": 2,
"builds": [{"src": "index.py", "use": "@vercel/python"}],
"routes": [{"src": "(.*)", "dest": "index.py"}],
},
indent=4,
)
)

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

Well this is VERY weird. We have two instances, both hosted on Vercel.

https://til.simonwillison.net/-/asgi-scope/thesession?sql=select+*+from+tunes+where+name+like+%22%25a%25%22%0D%0A

 'http_version': '1.1',
 'method': 'GET',
 'path': '/-/asgi-scope/thesession',
 'query_string': b'sql=select%20*%20from%20tunes%20where%20name%20like%20%22%25'
                 b'a%25%22%0D%0A',
 'raw_path': b'/-/asgi-scope/thesession',
 'root_path': '',
 'scheme': 'https',
 'server': ('til.simonwillison.net', 80),

But... this one with the exact same path and query string returns very different results:

https://thesession.vercel.app/-/asgi-scope/thesession?sql=select+*+from+tunes+where+name+like+%22%25a%25%22%0D%0A

 'http_version': '1.1',
 'method': 'GET',
 'path': '/-/asgi-scope/thesession',
 'query_string': b'sql=select * from tunes where name like "%a%"\r\n',
 'raw_path': b'/-/asgi-scope/thesession',
 'root_path': '',
 'scheme': 'https',
 'server': ('thesession.vercel.app', 80),

The one on thesession.vercel.app has had the query_string decoded. The one on til.simonwillison.net has not.

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

Another difference between the two (though not relevant to the bug we are investigating here):

https://til.simonwillison.net/-/asgi-scope/foo%2Fbar returns this:

 'path': '/-/asgi-scope/foo%2Fbar',
 'query_string': b'',
 'raw_path': b'/-/asgi-scope/foo%2Fbar',

https://thesession.vercel.app/-/asgi-scope/foo%2Fbar returns this:

 'path': '/-/asgi-scope/foo/bar',
 'query_string': b'',
 'raw_path': b'/-/asgi-scope/foo/bar',

According to the ASGI spec neither of those are correct - the expected return for that should be:

 'path': '/-/asgi-scope/foo/bar',
 'query_string': b'',
 'raw_path': b'/-/asgi-scope/foo%2Fbar',

from datasette-publish-vercel.

simonw avatar simonw commented on June 11, 2024

The most recent commit I can find to vercel/python that modified how path and raw_path were handled is this one: vercel/vercel@d3e6c2d#diff-349c8f0014a53eaa71bbc2f1a4c88f57eaedabb76ddfb65338d93f0b51122665

from datasette-publish-vercel.

styfle avatar styfle commented on June 11, 2024

https://til.simonwillison.net is using @vercel/python

https://thesession.vercel.app is using @now/python

You're seeing differences since @now/python hasn't received updates in 9 months

from datasette-publish-vercel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.