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

uri - fix traceback on multipart-form int value #74302

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/uri-multipart-int-value.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- uri - Fix traceback and provide error message when trying to use non-string or mapping for ``form-multipart`` body - https://github.com/ansible/ansible/issues/74276
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/common/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from ansible.module_utils.six import binary_type, text_type
from ansible.module_utils.common._collections_compat import Hashable, Mapping, Sequence
from ansible.module_utils.common._collections_compat import Hashable, Mapping, MutableMapping, Sequence


class ImmutableDict(Hashable, Mapping):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/action/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ansible.errors import AnsibleError, AnsibleAction, _AnsibleActionDone, AnsibleActionFail
from ansible.module_utils._text import to_native
from ansible.module_utils.common.collections import Mapping
from ansible.module_utils.common.collections import Mapping, MutableMapping
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import text_type
from ansible.plugins.action import ActionBase
Expand Down Expand Up @@ -61,7 +61,7 @@ def run(self, tmp=None, task_vars=None):
'body must be mapping, cannot be type %s' % body.__class__.__name__
)
for field, value in body.items():
if isinstance(value, text_type):
if not isinstance(value, MutableMapping):
continue
content = value.get('content')
filename = value.get('filename')
Expand Down
10 changes: 10 additions & 0 deletions test/integration/targets/uri/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@
- multipart.json.form.text_form_field1 == 'value1'
- multipart.json.form.text_form_field2 == 'value2'

# https://github.com/ansible/ansible/issues/74276 - verifies we don't have a traceback
- name: multipart/form-data with invalid value
uri:
url: https://{{ httpbin_host }}/post
method: POST
body_format: form-multipart
body:
integer_value: 1
register: multipart_invalid
failed_when: 'multipart_invalid.msg != "failed to parse body as form-multipart: value must be a string, or mapping, cannot be type int"'

- name: Validate invalid method
uri:
Expand Down