-
Notifications
You must be signed in to change notification settings - Fork 113
Don't try to parse the response json when not_modified #550
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jarovo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
872416c
to
9722942
Compare
/packit rebuild-failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey, @jarovo thanks for the contribution.
Would you consider adding some tests to this PR? I think this will greatly help to reproduce it too.
@@ -472,6 +472,10 @@ def stop(self, **kwargs) -> None: | |||
if response.status_code == requests.codes.not_modified: | |||
if kwargs.get("ignore", False): | |||
return | |||
else: | |||
raise APIError( | |||
response.text, response=response, explanation="Container already stopped." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you consider populating the response with response.json()["message"]
rather than a hard coded explanation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC The problem this PR attempted to solve was that podman compose tried to stop stopped container. There was no json-parseable body in the response and therefore the explanation couldn't be populated from the json in that case.
I found a place in the integration tests where I can stop the stopped container and expect the APIError. I've added the test in preceeding commit so we can see how it fails. Perhaps the fix should in the API -- to always produce json-parseable body.
Thank you for suggestion to write the tests. Is there some manual to help me running the tests? @inknos
…ontainers#550 Signed-off-by: Jaroslav Henner <[email protected]>
In case of not_modified (HTTP 304), there is no json in the response body. Json parsing fails like: ```python if response.status_code == requests.codes.not_modified: if kwargs.get("ignore", False): return body = response > raise APIError(body["cause"], response=response, explanation=body) E TypeError: 'APIResponse' object is not subscriptable .venv/lib/python3.12/site-packages/podman/domain/containers.py:477: TypeError ``` This patch fixes this in the way that APIError is rised with content from the text of the requests response Signed-off-by: Jaroslav Henner <[email protected]>
…ontainers#550 Signed-off-by: Jaroslav Henner <[email protected]>
Signed-off-by: Jaroslav Henner <[email protected]>
In case of not_modified (HTTP 304), there is no json in the response
body. Json parsing fails like:
This patch fixes this in the way that APIError is rised with content
from the text of the requests response