# Buggy code
def can_copy(self, obj):
    if self.save_messages:
        missing_ujt = []
        missing_credentials = []
        missing_inventories = []
        qs = obj.workflow_job_template_nodes
        qs = qs.prefetch_related(
            "unified_job_template", "inventory__use_role", "credential__use_role"
        )
        for node in qs.all():
            node_errors = {}
            if node.inventory and self.user not in node.inventory.use_role:
                missing_inventories.append(node.inventory.name)
            if node.credential and self.user not in node.credential.use_role:
                missing_credentials.append(node.credential.name)
            ujt = node.unified_job_template
            if ujt and not self.user.can_access(
                UnifiedJobTemplate, "start", ujt, validate_license=False
            ):
                missing_ujt.append(ujt.name)
            if node_errors:
                wfjt_errors[node.id] = node_errors
        if missing_ujt:
            self.messages["templates_unable_to_copy"] = missing_ujt
        if missing_credentials:
            self.messages["credentials_unable_to_copy"] = missing_credentials
        if missing_inventories:
            self.messages["inventories_unable_to_copy"] = missing_inventories

    return self.check_related(
        "organization",
        Organization,
        {"reference_obj": obj},
        role_field="workflow_admin_role",
        mandatory=True,
    )


# Traceback (Exception)
2018-03-23 00:17:12,246 ERROR    awx.main.scheduler Task awx.main.scheduler.tasks.run_task_manager encountered exception.
Traceback (most recent call last):
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/tasks.py", line 37, in run_task_manager
TaskManager().schedule()
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 629, in schedule
finished_wfjs = self._schedule()
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 614, in _schedule
self.spawn_workflow_graph_jobs(running_workflow_tasks)
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 196, in spawn_workflow_graph_jobs
job = spawn_node.unified_job_template.create_unified_job(**kv)
File "/usr/lib/python2.7/site-packages/awx/main/models/inventory.py", line 1500, in create_unified_job
return super(InventorySource, self).create_unified_job(**kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 393, in create_unified_job
unified_job.create_config_from_prompts(kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 880, in create_config_from_prompts
raise Exception('Unrecognized launch config field {}.'.format(field_name))
Exception: Unrecognized launch config field survey_passwords.
[2018-03-23 00:17:12,249: ERROR/MainProcess] Task awx.main.scheduler.tasks.run_task_manager[c29823d8-2fc7-40a4-ba2d-c79253cb4596] raised unexpected: Exception('Unrecognized launch config field survey_passwords.',)
Traceback (most recent call last):
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/tasks.py", line 37, in run_task_manager
TaskManager().schedule()
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 629, in schedule
finished_wfjs = self._schedule()
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 614, in _schedule
self.spawn_workflow_graph_jobs(running_workflow_tasks)
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 196, in spawn_workflow_graph_jobs
job = spawn_node.unified_job_template.create_unified_job(**kv)
File "/usr/lib/python2.7/site-packages/awx/main/models/inventory.py", line 1500, in create_unified_job
return super(InventorySource, self).create_unified_job(**kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 393, in create_unified_job
unified_job.create_config_from_prompts(kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 880, in create_config_from_prompts
raise Exception('Unrecognized launch config field {}.'.format(field_name))
Exception: Unrecognized launch config field survey_passwords.
[2018-03-23 00:17:26,777: INFO/MainProcess] Scaling down -2 processes.
[2018-03-23 00:17:26,778: DEBUG/MainProcess] basic.qos: prefetch_count->5432
[2018-03-23 00:17:31,896: DEBUG/Beat] beat: Synchronizing schedule...
[2018-03-23 00:17:31,916: INFO/Beat] Scheduler: Sending due task tower_scheduler (awx.main.tasks.awx_periodic_scheduler)
[2018-03-23 00:17:31,918: DEBUG/Beat] awx.main.tasks.awx_periodic_scheduler sent. id->c0466b22-2a05-4ac1-868c-0c28b34d0980
[2018-03-23 00:17:31,919: DEBUG/Beat] beat: Waking up now.
[2018-03-23 00:17:31,919: INFO/MainProcess] Received task: awx.main.tasks.awx_periodic_scheduler[c0466b22-2a05-4ac1-868c-0c28b34d0980] expires:[2018-03-23 00:17:51.917332+00:00]
[2018-03-23 00:17:31,919: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x30f8aa0> (args:(u'awx.main.tasks.awx_periodic_scheduler', u'c0466b22-2a05-4ac1-868c-0c28b34d0980', [], {}, {u'utc': True, u'is_eager': False, u'chord': None, u'group': None, u'args': [], u'retries': 0, u'delivery_info': {u'priority': None, u'redelivered': False, u'routing_key': u'tower', u'exchange': u'tower'}, u'expires': u'2018-03-23T00:17:51.917332+00:00', u'hostname': 'celery@awx', u'task': u'awx.main.tasks.awx_periodic_scheduler', u'callbacks': None, u'correlation_id': u'c0466b22-2a05-4ac1-868c-0c28b34d0980', u'errbacks': None, u'timelimit': [None, None], u'taskset': None, u'kwargs': {}, u'eta': None, u'reply_to': u'ebf3eb54-7a03-3352-a5e6-df53ebd2ceb6', u'id': u'c0466b22-2a05-4ac1-868c-0c28b34d0980', u'headers': {}}) kwargs:{})
[2018-03-23 00:17:31,921: DEBUG/MainProcess] Task accepted: awx.main.tasks.awx_periodic_scheduler[c0466b22-2a05-4ac1-868c-0c28b34d0980] pid:20372
2018-03-23 00:17:31,935 DEBUG    awx.main.tasks Last scheduler run was: 2018-03-23 00:17:01.909449+00:00
[2018-03-23 00:17:31,960: INFO/MainProcess] Task awx.main.tasks.awx_periodic_scheduler[c0466b22-2a05-4ac1-868c-0c28b34d0980] succeeded in 0.0399558200006s: None
[2018-03-23 00:17:31,973: INFO/Beat] Scheduler: Sending due task task_manager (awx.main.scheduler.tasks.run_task_manager)
[2018-03-23 00:17:31,974: DEBUG/Beat] awx.main.scheduler.tasks.run_task_manager sent. id->0b292032-d685-4beb-a953-9b5fe6e6c812
[2018-03-23 00:17:31,975: DEBUG/Beat] beat: Waking up in 18.41 seconds.
[2018-03-23 00:17:31,975: INFO/MainProcess] Received task: awx.main.scheduler.tasks.run_task_manager[0b292032-d685-4beb-a953-9b5fe6e6c812] expires:[2018-03-23 00:17:51.974214+00:00]
[2018-03-23 00:17:31,976: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x30f8aa0> (args:(u'awx.main.scheduler.tasks.run_task_manager', u'0b292032-d685-4beb-a953-9b5fe6e6c812', [], {}, {u'utc': True, u'is_eager': False, u'chord': None, u'group': None, u'args': [], u'retries': 0, u'delivery_info': {u'priority': 0, u'redelivered': False, u'routing_key': u'tower', u'exchange': u'tower'}, u'expires': u'2018-03-23T00:17:51.974214+00:00', u'hostname': 'celery@awx', u'task': u'awx.main.scheduler.tasks.run_task_manager', u'callbacks': None, u'correlation_id': u'0b292032-d685-4beb-a953-9b5fe6e6c812', u'errbacks': None, u'timelimit': [None, None], u'taskset': None, u'kwargs': {}, u'eta': None, u'reply_to': u'ebf3eb54-7a03-3352-a5e6-df53ebd2ceb6', u'id': u'0b292032-d685-4beb-a953-9b5fe6e6c812', u'headers': {}}) kwargs:{})
[2018-03-23 00:17:31,977: DEBUG/MainProcess] Task accepted: awx.main.scheduler.tasks.run_task_manager[0b292032-d685-4beb-a953-9b5fe6e6c812] pid:20372
2018-03-23 00:17:31,989 DEBUG    awx.main.scheduler Running Tower task manager.
2018-03-23 00:17:31,997 DEBUG    awx.main.scheduler Starting Scheduler
2018-03-23 00:17:32,187 WARNING  awx.main.models.unified_jobs Fields set(['extra_vars']) are not allowed as overrides.
[2018-03-23 00:17:32,187: WARNING/Worker-445] Fields set(['extra_vars']) are not allowed as overrides.
2018-03-23 00:17:32,219 ERROR    awx.main.scheduler Task awx.main.scheduler.tasks.run_task_manager encountered exception.
Traceback (most recent call last):
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/tasks.py", line 37, in run_task_manager
TaskManager().schedule()
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 629, in schedule
finished_wfjs = self._schedule()
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 614, in _schedule
self.spawn_workflow_graph_jobs(running_workflow_tasks)
File "/usr/lib/python2.7/site-packages/awx/main/scheduler/task_manager.py", line 196, in spawn_workflow_graph_jobs
job = spawn_node.unified_job_template.create_unified_job(**kv)
File "/usr/lib/python2.7/site-packages/awx/main/models/inventory.py", line 1500, in create_unified_job
return super(InventorySource, self).create_unified_job(**kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 393, in create_unified_job
unified_job.create_config_from_prompts(kwargs)
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 880, in create_config_from_prompts
raise Exception('Unrecognized launch config field {}.'.format(field_name))
Exception: Unrecognized launch config field survey_passwords.

# Fixed code
def can_copy(self, obj):
    if self.save_messages:
        missing_ujt = []
        missing_credentials = []
        missing_inventories = []
        qs = obj.workflow_job_template_nodes
        qs = qs.prefetch_related(
            "unified_job_template", "inventory__use_role", "credentials__use_role"
        )
        for node in qs.all():
            node_errors = {}
            if node.inventory and self.user not in node.inventory.use_role:
                missing_inventories.append(node.inventory.name)
            for cred in node.credentials.all():
                if self.user not in cred.use_role:
                    missing_credentials.append(node.credential.name)
            ujt = node.unified_job_template
            if ujt and not self.user.can_access(
                UnifiedJobTemplate, "start", ujt, validate_license=False
            ):
                missing_ujt.append(ujt.name)
            if node_errors:
                wfjt_errors[node.id] = node_errors
        if missing_ujt:
            self.messages["templates_unable_to_copy"] = missing_ujt
        if missing_credentials:
            self.messages["credentials_unable_to_copy"] = missing_credentials
        if missing_inventories:
            self.messages["inventories_unable_to_copy"] = missing_inventories

    return self.check_related(
        "organization",
        Organization,
        {"reference_obj": obj},
        role_field="workflow_admin_role",
        mandatory=True,
    )