Skip to content

Commit

Permalink
dnf: don't return fail_json['msg'] as list (#65302)
Browse files Browse the repository at this point in the history
Although it's not enforced that fail_json['msg'] should be a string
[1], I think it is pretty strongly implied.

In this case the failure_response['msg'] is sent through as the
fail_json['msg'], and the trailing commas here turn it into a tuple.
It's not clear if this is a typo or intended, but it does cause
problems for callbacks that expect this as a string (e.g. [2]).

Since there seems no point to having these values as a tuple, remove
the trailing commas so they return a string as per everywhere else.

[1] https://github.com/ansible/ansible/blob/4c589661c2add45023f2bff9203e0c4e11efe5f6/lib/ansible/module_utils/basic.py#L2078
[2] https://review.opendev.org/#/c/696081
  • Loading branch information
ianw authored and ansibot committed Dec 4, 2019
1 parent 770430f commit fc54ae9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/65302-dnf-msg-return.yml
@@ -0,0 +1,3 @@
bugfixes:
- dnf module - Ensure the modules exit_json['msg'] response is
always string, not sometimes a tuple.
4 changes: 2 additions & 2 deletions lib/ansible/modules/packaging/os/dnf.py
Expand Up @@ -1165,7 +1165,7 @@ def ensure(self):
else:
response['changed'] = True
if failure_response['failures']:
failure_response['msg'] = 'Failed to install some of the specified packages',
failure_response['msg'] = 'Failed to install some of the specified packages'
self.module.fail_json(**failure_response)
if self.module.check_mode:
response['msg'] = "Check mode: No changes made, but would have if not in check mode"
Expand Down Expand Up @@ -1195,7 +1195,7 @@ def ensure(self):
response['results'].append("Removed: {0}".format(package))

if failure_response['failures']:
failure_response['msg'] = 'Failed to install some of the specified packages',
failure_response['msg'] = 'Failed to install some of the specified packages'
self.module.exit_json(**response)
self.module.exit_json(**response)
except dnf.exceptions.DepsolveError as e:
Expand Down

0 comments on commit fc54ae9

Please sign in to comment.