From 4b2be9850e0c8b676842f42f1876c7c453d48630 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 18 Jul 2017 12:12:02 -0400 Subject: [PATCH] copy adhoc events properly for stdout downloads see: #7100 --- awx/api/views.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index a12214024f..dfb57da156 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -4362,8 +4362,18 @@ class UnifiedJobStdout(RetrieveAPIView): write_fd = open(unified_job.result_stdout_file, 'w') with connection.cursor() as cursor: try: - cursor.copy_expert("copy (select stdout from main_jobevent where job_id={} order by start_line) to stdout".format(unified_job.id), - write_fd) + tablename, related_name = { + Job: ('main_jobevent', 'job_id'), + AdHocCommand: ('main_adhoccommandevent', 'ad_hoc_command_id'), + }[unified_job.__class__] + cursor.copy_expert( + "copy (select stdout from {} where {}={} order by start_line) to stdout".format( + tablename, + related_name, + unified_job.id + ), + write_fd + ) write_fd.close() subprocess.Popen("sed -i 's/\\\\r\\\\n/\\n/g' {}".format(unified_job.result_stdout_file), shell=True).wait()