Skip to content

Commit

Permalink
fix: client is sending a body in a GET and HEAD requests (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Jan 24, 2025
1 parent 9e7cca4 commit 6947a53
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ jobs:
run: make run_tests

- name: Upload coverage to Coveralls
if: ${{ matrix.python-version }} == "3.12"
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-error: false

release-please:
needs: test
Expand Down
2 changes: 1 addition & 1 deletion postgrest/_async/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self.http_method = http_method
self.headers = headers
self.params = params
self.json = json
self.json = None if http_method in {"GET", "HEAD"} else json

async def execute(self) -> APIResponse[_ReturnT]:
"""Execute the query.
Expand Down
2 changes: 1 addition & 1 deletion postgrest/_sync/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self.http_method = http_method
self.headers = headers
self.params = params
self.json = json
self.json = None if http_method in {"GET", "HEAD"} else json

def execute(self) -> APIResponse[_ReturnT]:
"""Execute the query.
Expand Down
2 changes: 1 addition & 1 deletion tests/_async/test_filter_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_constructor(filter_request_builder: AsyncFilterRequestBuilder):
assert len(builder.headers) == 0
assert len(builder.params) == 0
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None
assert not builder.negate_next


Expand Down
2 changes: 1 addition & 1 deletion tests/_async/test_query_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def test_constructor(query_request_builder: AsyncQueryRequestBuilder):
assert len(builder.headers) == 0
assert len(builder.params) == 0
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None
6 changes: 3 additions & 3 deletions tests/_async/test_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ def test_select(self, request_builder: AsyncRequestBuilder):
assert builder.params["select"] == "col1,col2"
assert builder.headers.get("prefer") is None
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None

def test_select_with_count(self, request_builder: AsyncRequestBuilder):
builder = request_builder.select(count=CountMethod.exact)

assert builder.params["select"] == "*"
assert builder.headers["prefer"] == "count=exact"
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None

def test_select_with_head(self, request_builder: AsyncRequestBuilder):
builder = request_builder.select("col1", "col2", head=True)

assert builder.params.get("select") == "col1,col2"
assert builder.headers.get("prefer") is None
assert builder.http_method == "HEAD"
assert builder.json == {}
assert builder.json == None

def test_select_as_csv(self, request_builder: AsyncRequestBuilder):
builder = request_builder.select("*").csv()
Expand Down
2 changes: 1 addition & 1 deletion tests/_sync/test_filter_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_constructor(filter_request_builder: SyncFilterRequestBuilder):
assert len(builder.headers) == 0
assert len(builder.params) == 0
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None
assert not builder.negate_next


Expand Down
2 changes: 1 addition & 1 deletion tests/_sync/test_query_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def test_constructor(query_request_builder: SyncQueryRequestBuilder):
assert len(builder.headers) == 0
assert len(builder.params) == 0
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None
6 changes: 3 additions & 3 deletions tests/_sync/test_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ def test_select(self, request_builder: SyncRequestBuilder):
assert builder.params["select"] == "col1,col2"
assert builder.headers.get("prefer") is None
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None

def test_select_with_count(self, request_builder: SyncRequestBuilder):
builder = request_builder.select(count=CountMethod.exact)

assert builder.params["select"] == "*"
assert builder.headers["prefer"] == "count=exact"
assert builder.http_method == "GET"
assert builder.json == {}
assert builder.json == None

def test_select_with_head(self, request_builder: SyncRequestBuilder):
builder = request_builder.select("col1", "col2", head=True)

assert builder.params.get("select") == "col1,col2"
assert builder.headers.get("prefer") is None
assert builder.http_method == "HEAD"
assert builder.json == {}
assert builder.json == None

def test_select_as_csv(self, request_builder: SyncRequestBuilder):
builder = request_builder.select("*").csv()
Expand Down

0 comments on commit 6947a53

Please sign in to comment.