Ensure configure-central task is indempotent#14
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mgoerens The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
| message = None | ||
| try: | ||
| message = response.json().get("message") | ||
| except requests.exceptions.JSONDecodeError: |
There was a problem hiding this comment.
This only ensures that JSON has failed. Would ass as well for AttributeError.
There was a problem hiding this comment.
I believe we're good here, unless I'm missing something that could raise AttributeError:
Response.json()only can raiserequests.exceptions.JSONDecodeError.dict.get()never raises exceptions, by default it returnsNoneif the key isn't present in the dictionary.
There was a problem hiding this comment.
response.json() assumes that it is returning dict. Error could be like this
AttributeError: 'list' object has no attribute 'get' which can create unexpected problem. Based on Gemini there is alternative:
try:
data = response.json()
message = data.get("message") if isinstance(data, dict) else None
except requests.exceptions.JSONDecodeError:
pass
There was a problem hiding this comment.
I see, good catch. I went to your initial suggestion and also switched to using suppress as I think this fits nicely for this use case.
ae236f5 to
ff94b98
Compare
The task would previously fail if the image integration was already configured. Signed-off-by: Matthias Goerens <mgoerens@redhat.com>
ff94b98 to
9731919
Compare
The task would previously fail if the image integration was already configured.