Repository navigation
fix: do not mutate httpx client inside storage, postgrest and functions - #1249
Conversation
instead, use `yarl.URL` to parse and manipulate the URL in a stateless way, by returning a new url when paths are appended
|
I do think letting the |
Pull Request Test Coverage Report for Build 18354726720Details
💛 - Coveralls |
silentworks
left a comment
There was a problem hiding this comment.
I will pull this code down and test against my local codebase.
It was either this or passing every parameter that |
Thank you, please let me know of the results.
The problem is that it is still happening, |
|
Just noticed that this problem is not only on these two libraries, |
|
@o-santi I'm getting an error while using these changes in my test setup locally. The error is below. |
silentworks
left a comment
There was a problem hiding this comment.
Async/SyncBucketActionsMixin class is missing the base_url and only has the path as the URL hence the error above. This needs to be updated to match the Async/SyncStorageBucketAPI use of base_url.
silentworks
left a comment
There was a problem hiding this comment.
This looks good and is working now.
Fixes #1984. Alternative to #1985. ## Problem `relative_path_to_parts()` parsed every object key with `yarl.URL`. A key is not a URL, so parts of it were read as URL syntax and dropped: | Key | Sent as | | -------------------------------- | --------------- | | `backup-2024-01-01T10:00:00.sql` | `00:00.sql` | | `user:42/avatar.png` | `42/avatar.png` | | `what?.txt` | `what` | | `report#1.pdf` | `report` | | `//folder/file.png` | `file.png` | Every method that takes a path used the wrong key, so different keys could overwrite each other and downloads could return another object's bytes. This came in with #1249. Before that, the key was formatted into the request path as a plain string. ## Fix Split the key on `/` after stripping leading slashes, and percent-decode each part as before. `joinpath()` already encodes each part when the request URL is built, so `:` is kept and `?` and `#` are sent as `%3F` and `%23`. Percent-decoding is kept so that a pre-encoded key such as `a%20b.png` still resolves to `a b.png`, as it did on earlier v2 releases. The only input that behaves differently is a full URL passed as a key, such as `https://host/a/b`, which used to be reduced to `a/b`. ## Tests `tests/test_object_paths.py` checks the request path sent by `upload()` and the URL returned by `get_public_url()` for both clients. Against the old function, 15 of 33 cases fail. From `src/storage`: - `uv run --frozen --package storage3 pytest -o addopts="" tests/test_object_paths.py tests/test_upload_headers.py tests/test_utils.py tests/test_client.py`: 119 passed. - `uv run --frozen --package storage3 --group mypy mypy src/storage3 tests`: no issues. - `ruff format --check` and `ruff check`: passed. The infra-backed storage suite was not run locally.
What kind of change does this PR introduce?
Fix both
storageandpostgrestto not mutate external httpx client, given it is shared, by instead keeping their own copy of their parameters to pass into the request call. In order to properly manipulate URLs without mutation, I've decided to add theyarldependency, which returns a new object upon path manipulation.For the
postgrestlibrary, I've also decided to factor out all of the parameters that go into a request in aRequestConfigobject, for it is very easy to miss a spot otherwise. I've had to change the tests to account for this. However, I think this greatly simplifies most of the libraries, as 99% of the code does not need to be async/sync, and can be stated only once in a further rewrite.Additional context
Should fix #1245.