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

ci: add requests compatiblity check #312

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
100 changes: 100 additions & 0 deletions .github/workflows/deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Check Compability
on:
- pull_request
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
UV_SYSTEM_PYTHON: true
jobs:
check-requests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
requests-version:
- '2.32.3'
- '2.32.2'
- '2.31.0'
- '2.30.0'
- '2.29.0'
- '2.28.2'
- '2.28.1'
- '2.28.0'
- '2.27.1'
- '2.27.0'
- '2.26.0'
- '2.25.1'
- '2.25.0'
- '2.24.0'
- '2.23.0'
- '2.22.0'
- '2.21.0'
- '2.20.1'
- '2.20.0'
- '2.19.1'
- '2.19.0'
- '2.18.4'
- '2.18.3'
- '2.18.2'
- '2.18.1'
- '2.18.0'
- '2.17.3'
- '2.17.2'
- '2.17.1'
- '2.17.0'
- '2.16.5'
- '2.16.4'
- '2.16.3'
- '2.16.2'
- '2.16.1'
- '2.16.0'
- '2.15.1'
- '2.15.0'
- '2.14.2'
- '2.14.1'
- '2.14.0'
- '2.13.0'
- '2.12.5'
- '2.12.4'
- '2.12.3'
- '2.12.2'
- '2.12.1'
- '2.12.0'
- '2.11.1'
- '2.11.0'
- '2.10.0'
- '2.9.2'
- '2.9.1'
- '2.9.0'
- '2.8.1'
- '2.8.0'
- '2.7.0'
- '2.6.2'
- '2.6.1'
- '2.6.0'
- '2.5.3'
- '2.5.2'
- '2.5.1'
- '2.5.0'
- '2.4.3'
- '2.4.2'
- '2.4.1'
- '2.4.0'
- '2.3.0'
- '2.2.1'
- '2.2.0'
- '2.1.0'
- '2.0.1'
- '2.0.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like overkill. Why not just test on 2.0.0, and if we find that we need to add a specific version later, we can?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right. This is just an attempt at understanding where things break. This latest commit is broken, but if you look here, you will see that things break starting with 2.27.1 and earlier. This issue stems from how we are catching errors in the hooks module.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, clever

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
check-latest: true
cache: 'pip'
- run: make dev
- run: make deps
- run: uv pip install requests==${{ matrix.requests-version }}
- run: make test
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"requests>=2.31.0,<3",
"requests>=2,<3",
"packaging",
"typing-extensions"
]
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
requests==2.32.2
packaging==24.1
typing-extensions==4.12.2
requests
packaging
typing-extensions
11 changes: 6 additions & 5 deletions src/posit/connect/hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import warnings
from http.client import responses

from requests import JSONDecodeError, Response
import requests
from requests import Response

from .errors import ClientError

Expand All @@ -14,11 +16,10 @@ def handle_errors(response: Response, *args, **kwargs) -> Response:
message = data["error"]
payload = data.get("payload")
http_status = response.status_code
http_status_message = responses[http_status]
http_status_message = responses.get(http_status, "Unknown status")
raise ClientError(error_code, message, http_status, http_status_message, payload)
except JSONDecodeError:
# No JSON error message from Connect, so just raise
response.raise_for_status()
finally:
response.raise_for_status() # Raise if no JSON error is available
return response


Expand Down
6 changes: 2 additions & 4 deletions tests/posit/connect/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ def test_client_error():
with pytest.raises(ClientError):
handle_errors(response)


@patch("posit.connect.hooks.JSONDecodeError")
def test_client_error_without_payload(JSONDecodeError):
def test_client_error_without_payload():
response = Mock()
response.status_code = 404
response.json = Mock(side_effect=JSONDecodeError())
response.json = Mock(side_effect=Exception())
response.raise_for_status = Mock(side_effect=Exception())
with pytest.raises(Exception):
handle_errors(response)
Expand Down
Loading