# Buggy code
def create_config_from_prompts(self, kwargs):
    """
    Create a launch configuration entry for this job, given prompts
    returns None if it can not be created
    """
    if self.unified_job_template is None:
        return None
    JobLaunchConfig = self._meta.get_field("launch_config").related_model
    config = JobLaunchConfig(job=self)
    valid_fields = self.unified_job_template.get_ask_mapping().keys()
    if hasattr(self, "extra_vars"):
        valid_fields.extend(["survey_passwords", "extra_vars"])
    for field_name, value in kwargs.items():
        if field_name not in valid_fields:
            raise Exception("Unrecognized launch config field {}.".format(field_name))
        if field_name == "credentials":
            continue
        key = field_name
        if key == "extra_vars":
            key = "extra_data"
        setattr(config, key, value)
    config.save()

    job_creds = set(kwargs.get("credentials", [])) - set(
        self.unified_job_template.credentials.all()
    )
    if job_creds:
        config.credentials.add(*job_creds)
    return config


# 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 create_config_from_prompts(self, kwargs):
    """
    Create a launch configuration entry for this job, given prompts
    returns None if it can not be created
    """
    if self.unified_job_template is None:
        return None
    JobLaunchConfig = self._meta.get_field("launch_config").related_model
    config = JobLaunchConfig(job=self)
    valid_fields = self.unified_job_template.get_ask_mapping().keys()
    # Special cases allowed for workflows
    if hasattr(self, "extra_vars"):
        valid_fields.extend(["survey_passwords", "extra_vars"])
    else:
        kwargs.pop("survey_passwords", None)
    for field_name, value in kwargs.items():
        if field_name not in valid_fields:
            raise Exception("Unrecognized launch config field {}.".format(field_name))
        if field_name == "credentials":
            continue
        key = field_name
        if key == "extra_vars":
            key = "extra_data"
        setattr(config, key, value)
    config.save()

    job_creds = set(kwargs.get("credentials", [])) - set(
        self.unified_job_template.credentials.all()
    )
    if job_creds:
        config.credentials.add(*job_creds)
    return config