-
-
Notifications
You must be signed in to change notification settings - Fork 857
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
ASGITransport does not correctly simulate raw_path in the scope #1356
Comments
The fix here may be as straight-forward as adding this line to the code that constructs the scope: "raw_path": path, |
Since we're here - one related issue. I'm interested in cases where you'd like to use the client for making the request, but need some information that is lost by the time you've sent an HTTP response. In particular eg. making a request and then verifying that the correct HTML template was used, and contains some particular context. Have discussed some of this provisionally against the ASGI spec here... django/asgiref#135 Curious if any of that has relevance to any of your Datasette tests? |
* Add raw_path to scope in ASGITransport, closes #1356 * Tweaked test
Extra debug/test information in ASGI messages is an interesting idea. I've been working around that using the ASGI equivalent of threadlocals (context vars etc) - I usually avoid threadlocal-equivalents like the plague, but I've come to accept them for debugging/observability style mechanisms where you need to know what happened for informational puproses without having to re-engineer your entire stack to pass tracking values around. Likewise, with ASGI I've thought about doing this using request IDs (also known as correlation IDs) that are set in an HTTP header and can be used to establish a key/value store that has been populated with data during the request. These workarounds are working OK for me at the moment, but I'd certainly be keen to try out a less global-variable approach if one was available. |
I'm trying to switch Datasette's internal tests over to using
httpx
withAsyncClient
.This has almost worked perfectly, but I've run into one problem: it looks like the
ASGITransport
class used by theAsyncClient(app=asgi_app)
mechanism does not correctly simulate theraw_path
andpath
keys.Here's the code in question:
httpx/httpx/_transports/asgi.py
Lines 82 to 97 in 92ca4d0
As you can see, it's not populating
raw_path
even though that's part of the ASGI spec.This matters for Datasette because it supports this URL: https://latest.datasette.io/fixtures/table%2Fwith%2Fslashes.csv - which refers to a SQLite database table called
table/with/slashes.csv
(a weird table name but that's test cases for you). The way it does this is through careful decoding of theraw_path
ASGI scope variable.Here are my notes when I first ran into this limitation of ASGITransport: simonw/datasette#1000 (comment)
The text was updated successfully, but these errors were encountered: