Skip to content
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

Fix bug in api provider #99

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

- Test against Python 3.13 (bumped asyncpg to `0.30.*` and aiohttp to `3.10.*`).

- Fixed a bug in (Sync)ApiProvider and Gateway: if a query parameter with value `None`
is presented, this now hides the query parameter from the generated url. Before,
it resulted in `path?foo=None`.


## 0.18.0 (2024-10-21)
----------------------
Expand Down
5 changes: 4 additions & 1 deletion clean_python/api_client/api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ def join(url: str, path: str, trailing_slash: bool = False) -> str:


def add_query_params(url: str, params: Json | None) -> str:
# explicitly filter out None values
if params is None:
return url
return url + "?" + urlencode(params, doseq=True)
params = {k: v for k, v in params.items() if v is not None}
query_str = urlencode(params, doseq=True)
return url + "?" + query_str if query_str else url


class FileFormPost(ValueObject):
Expand Down
3 changes: 3 additions & 0 deletions tests/api_client/test_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ async def test_post_json(api_provider: ApiProvider, response, request_m):
("bar/", {"a": 2}, "http://testserver/foo/bar?a=2"),
("", {"a": [1, 2]}, "http://testserver/foo?a=1&a=2"),
("", {"a": 1, "b": "foo"}, "http://testserver/foo?a=1&b=foo"),
("", {"a": None}, "http://testserver/foo"),
("", {"a": ""}, "http://testserver/foo?a="),
("", {"a": []}, "http://testserver/foo"),
],
)
async def test_url(api_provider: ApiProvider, path, params, expected_url, request_m):
Expand Down
3 changes: 3 additions & 0 deletions tests/api_client/test_sync_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def test_post_json(api_provider: SyncApiProvider, response):
("bar/", {"a": 2}, "http://testserver/foo/bar?a=2"),
("", {"a": [1, 2]}, "http://testserver/foo?a=1&a=2"),
("", {"a": 1, "b": "foo"}, "http://testserver/foo?a=1&b=foo"),
("", {"a": None}, "http://testserver/foo"),
("", {"a": ""}, "http://testserver/foo?a="),
("", {"a": []}, "http://testserver/foo"),
],
)
def test_url(api_provider: SyncApiProvider, path, params, expected_url):
Expand Down
Loading