Fix uri form-multipart to not overwrite filename to allow retries (#85010)

pull/85798/head
Zdeněk Vydra 3 months ago committed by GitHub
parent ddbedc6ac6
commit 60511c2a08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- uri - fix form-multipart file not being found when task is retried (https://github.com/ansible/ansible/issues/85009)

@ -7,6 +7,7 @@ from __future__ import annotations
import collections.abc as _c
import os
from copy import deepcopy
from ansible.errors import AnsibleActionFail
from ansible.module_utils.parsing.convert_bool import boolean
@ -53,7 +54,8 @@ class ActionModule(ActionBase):
raise AnsibleActionFail(
'body must be mapping, cannot be type %s' % body.__class__.__name__
)
for field, value in body.items():
new_body = deepcopy(body)
for field, value in new_body.items():
if not isinstance(value, _c.MutableMapping):
continue
content = value.get('content')
@ -70,7 +72,7 @@ class ActionModule(ActionBase):
value['filename'] = tmp_src
self._transfer_file(filename, tmp_src)
self._fixup_perms2((self._connection._shell.tmpdir, tmp_src))
kwargs['body'] = body
kwargs['body'] = new_body
new_module_args = self._task.args | kwargs

@ -477,6 +477,25 @@
register: multipart_invalid
failed_when: '"failed to parse body as form-multipart: value must be a string, or mapping, cannot be type" not in multipart_invalid.msg'
- name: multipart/form-data with file and retry
uri:
url: https://{{ httpbin_host }}/post
method: POST
body_format: form-multipart
body:
file:
filename: formdata.txt
retries: 1
delay: 0.01
register: result
failed_when: result is failed or result.attempts == 1
- name: Assert multipart/form-data with file and retry
assert:
that:
- result.json.files.file | b64decode == '_multipart/form-data_\n'
- result.attempts == 2
- name: Validate invalid method
uri:
url: https://{{ httpbin_host }}/anything

Loading…
Cancel
Save