# Buggy code
def update_raw_data(self, data):
    data = super(JobRelaunch, self).update_raw_data(data)
    try:
        obj = self.get_object()
    except PermissionDenied:
        return data
    if obj:
        needed_passwords = obj.passwords_needed_to_start
        if needed_passwords:
            data["credential_passwords"] = {}
            for p in needed_passwords:
                data["credential_passwords"][p] = ""
        else:
            data.pop("credential_passwords")
    return data


# Traceback (socket.error)
web_1        | error: [Errno 111] Connection refused
web_1        | 2018-02-28 15:04:22,988 ERROR    django.request Internal Server Error: /api/v2/instances/1/
web_1        | Traceback (most recent call last):
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1        |     response = get_response(request)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
web_1        |     response = self._get_response(request)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1        |     response = self.process_exception_by_middleware(e, request)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1        |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
web_1        |     return func(*args, **kwargs)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1        |     return view_func(*args, **kwargs)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
web_1        |     return self.dispatch(request, *args, **kwargs)
web_1        |   File "/usr/lib/python2.7/site-packages/awx/api/generics.py", line 284, in dispatch
web_1        |     return super(APIView, self).dispatch(request, *args, **kwargs)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/views.py", line 489, in dispatch
web_1        |     response = self.handle_exception(exc)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/views.py", line 449, in handle_exception
web_1        |     self.raise_uncaught_exception(exc)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/views.py", line 486, in dispatch
web_1        |     response = handler(request, *args, **kwargs)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/generics.py", line 257, in put
web_1        |     return self.update(request, *args, **kwargs)
web_1        |   File "/usr/lib/python2.7/site-packages/awx/api/views.py", line 594, in update
web_1        |     handle_ha_toplogy_changes.apply_async()
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/task.py", line 573, in apply_async
web_1        |     **dict(self._get_exec_options(), **options)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/base.py", line 354, in send_task
web_1        |     reply_to=reply_to or self.oid, **options
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/amqp.py", line 310, in publish_task
web_1        |     **kwargs
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/messaging.py", line 172, in publish
web_1        |     routing_key, mandatory, immediate, exchange, declare)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 470, in _ensured
web_1        |     interval_max)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 382, in ensure_connection
web_1        |     interval_start, interval_step, interval_max, callback)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/utils/__init__.py", line 246, in retry_over_time
web_1        |     return fun(*args, **kwargs)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 250, in connect
web_1        |     return self.connection
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 756, in connection
web_1        |     self._connection = self._establish_connection()
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 711, in _establish_connection
web_1        |     conn = self.transport.establish_connection()
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
web_1        |     conn = self.Connection(**opts)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 165, in __init__
web_1        |     self.transport = self.Transport(host, connect_timeout, ssl)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 186, in Transport
web_1        |     return create_transport(host, connect_timeout, ssl)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/transport.py", line 299, in create_transport
web_1        |     return TCPTransport(host, connect_timeout)
web_1        |   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/transport.py", line 95, in __init__
web_1        |     raise socket.error(last_err)

# Fixed code
def update_raw_data(self, data):
    data = super(JobRelaunch, self).update_raw_data(data)
    try:
        obj = self.get_object()
    except PermissionDenied:
        return data
    if obj:
        needed_passwords = obj.passwords_needed_to_start
        if needed_passwords:
            data["credential_passwords"] = {}
            for p in needed_passwords:
                data["credential_passwords"][p] = ""
        else:
            data.pop("credential_passwords", None)
    return data