From c31424a92479f3c36ca9d2be01101d85b6c74437 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 28 Jul 2021 08:35:08 +0200 Subject: [PATCH] django_manage - using list instead of string in run_command() (#3098) (#3102) * django_manage - using list instead of string in run_command() * added changelog fragment (cherry picked from commit 0b70b3baff58f26e6a3dac12ed125d3fe4e9195a) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- .../3098-django_manage-cmd-list.yaml | 2 + .../web_infrastructure/django_manage.py | 40 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 changelogs/fragments/3098-django_manage-cmd-list.yaml diff --git a/changelogs/fragments/3098-django_manage-cmd-list.yaml b/changelogs/fragments/3098-django_manage-cmd-list.yaml new file mode 100644 index 0000000000..8522059ff6 --- /dev/null +++ b/changelogs/fragments/3098-django_manage-cmd-list.yaml @@ -0,0 +1,2 @@ +bugfixes: + - django_manage - refactor to call ``run_command()`` passing command as a list instead of string (https://github.com/ansible-collections/community.general/pull/3098). diff --git a/plugins/modules/web_infrastructure/django_manage.py b/plugins/modules/web_infrastructure/django_manage.py index ba38abd90e..98ffdc446b 100644 --- a/plugins/modules/web_infrastructure/django_manage.py +++ b/plugins/modules/web_infrastructure/django_manage.py @@ -256,20 +256,20 @@ def main(): argument_spec=dict( command=dict(required=True, type='str'), project_path=dict(required=True, type='path', aliases=['app_path', 'chdir']), - settings=dict(default=None, required=False, type='path'), - pythonpath=dict(default=None, required=False, type='path', aliases=['python_path']), - virtualenv=dict(default=None, required=False, type='path', aliases=['virtual_env']), + settings=dict(type='path'), + pythonpath=dict(type='path', aliases=['python_path']), + virtualenv=dict(type='path', aliases=['virtual_env']), - apps=dict(default=None, required=False), - cache_table=dict(default=None, required=False, type='str'), - clear=dict(default=False, required=False, type='bool'), - database=dict(default=None, required=False, type='str'), - failfast=dict(default=False, required=False, type='bool', aliases=['fail_fast']), - fixtures=dict(default=None, required=False, type='str'), - testrunner=dict(default=None, required=False, type='str', aliases=['test_runner']), - skip=dict(default=None, required=False, type='bool'), - merge=dict(default=None, required=False, type='bool'), - link=dict(default=None, required=False, type='bool'), + apps=dict(), + cache_table=dict(type='str'), + clear=dict(default=False, type='bool'), + database=dict(type='str'), + failfast=dict(default=False, type='bool', aliases=['fail_fast']), + fixtures=dict(type='str'), + testrunner=dict(type='str', aliases=['test_runner']), + skip=dict(type='bool'), + merge=dict(type='bool'), + link=dict(type='bool'), ), ) @@ -279,8 +279,6 @@ def main(): for param in specific_params: value = module.params[param] - if param in specific_boolean_params: - value = module.boolean(value) if value and param not in command_allowed_param_map[command]: module.fail_json(msg='%s param is incompatible with command=%s' % (param, command)) @@ -290,23 +288,23 @@ def main(): _ensure_virtualenv(module) - cmd = "./manage.py %s" % (command, ) + cmd = ["./manage.py", command] if command in noinput_commands: - cmd = '%s --noinput' % cmd + cmd.append("--noinput") for param in general_params: if module.params[param]: - cmd = '%s --%s=%s' % (cmd, param, module.params[param]) + cmd.append('--%s=%s' % (param, module.params[param])) for param in specific_boolean_params: - if module.boolean(module.params[param]): - cmd = '%s --%s' % (cmd, param) + if module.params[param]: + cmd.append('--%s' % param) # these params always get tacked on the end of the command for param in end_of_command_params: if module.params[param]: - cmd = '%s %s' % (cmd, module.params[param]) + cmd.append(module.params[param]) rc, out, err = module.run_command(cmd, cwd=project_path) if rc != 0: