Skip to content

Conversation

@jarovo
Copy link

@jarovo jarovo commented May 18, 2025

In case of not_modified (HTTP 304), there is no json in the response
body. Json parsing fails like:

        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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jarovo
Once this PR has been reviewed and has the lgtm label, please assign giuseppe for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jarovo jarovo force-pushed the main branch 3 times, most recently from 872416c to 9722942 Compare May 18, 2025 14:24
@inknos
Copy link
Contributor

inknos commented May 18, 2025

/packit rebuild-failed

Copy link
Contributor

@inknos inknos left a 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.

return
else:
raise APIError(
response.text, response=response, explanation="Container already stopped."
Copy link
Contributor

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?

Copy link
Author

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

jarovo added 4 commits May 23, 2025 13:45
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]>
Signed-off-by: Jaroslav Henner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants