# Buggy code
def determine_actions(self, request, view):
    actions = super(SublistAttachDetatchMetadata, self).determine_actions(request, view)
    method = "POST"
    if method in actions:
        for field in actions[method]:
            if field == "id":
                continue
            actions[method].pop(field)
    return actions


# Traceback (RuntimeError)
awx_1        | 18:58:54 uwsgi.1      | 2019-02-27 18:58:54,069 ERROR    django.request Internal Server Error: /api/v2/instance_groups/1/instances/
awx_1        | 18:58:54 uwsgi.1      | Traceback (most recent call last):
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
awx_1        | 18:58:54 uwsgi.1      |     response = get_response(request)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/wsgi.py", line 72, in _legacy_get_response
awx_1        | 18:58:54 uwsgi.1      |     return super(AWXWSGIHandler, self)._legacy_get_response(request)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
awx_1        | 18:58:54 uwsgi.1      |     response = self._get_response(request)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
awx_1        | 18:58:54 uwsgi.1      |     response = self.process_exception_by_middleware(e, request)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
awx_1        | 18:58:54 uwsgi.1      |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/usr/lib64/python3.6/contextlib.py", line 52, in inner
awx_1        | 18:58:54 uwsgi.1      |     return func(*args, **kwds)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
awx_1        | 18:58:54 uwsgi.1      |     return view_func(*args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/views/generic/base.py", line 68, in view
awx_1        | 18:58:54 uwsgi.1      |     return self.dispatch(request, *args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/api/generics.py", line 334, in dispatch
awx_1        | 18:58:54 uwsgi.1      |     return super(APIView, self).dispatch(request, *args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 494, in dispatch
awx_1        | 18:58:54 uwsgi.1      |     response = self.handle_exception(exc)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 454, in handle_exception
awx_1        | 18:58:54 uwsgi.1      |     self.raise_uncaught_exception(exc)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 491, in dispatch
awx_1        | 18:58:54 uwsgi.1      |     response = handler(request, *args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 505, in options
awx_1        | 18:58:54 uwsgi.1      |     data = self.metadata_class().determine_metadata(request, self)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/api/metadata.py", line 198, in determine_metadata
awx_1        | 18:58:54 uwsgi.1      |     metadata = super(Metadata, self).determine_metadata(request, view)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/metadata.py", line 69, in determine_metadata
awx_1        | 18:58:54 uwsgi.1      |     actions = self.determine_actions(request, view)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/api/metadata.py", line 256, in determine_actions
awx_1        | 18:58:54 uwsgi.1      |     for field in actions[method]:
awx_1        | 18:58:54 uwsgi.1      | RuntimeError: OrderedDict mutated during iteration
awx_1        | 18:58:54 uwsgi.1      | 2019-02-27 18:58:54,069 ERROR    django.request Internal Server Error: /api/v2/instance_groups/1/instances/
awx_1        | 18:58:54 uwsgi.1      | Traceback (most recent call last):
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
awx_1        | 18:58:54 uwsgi.1      |     response = get_response(request)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/wsgi.py", line 72, in _legacy_get_response
awx_1        | 18:58:54 uwsgi.1      |     return super(AWXWSGIHandler, self)._legacy_get_response(request)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
awx_1        | 18:58:54 uwsgi.1      |     response = self._get_response(request)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
awx_1        | 18:58:54 uwsgi.1      |     response = self.process_exception_by_middleware(e, request)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
awx_1        | 18:58:54 uwsgi.1      |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/usr/lib64/python3.6/contextlib.py", line 52, in inner
awx_1        | 18:58:54 uwsgi.1      |     return func(*args, **kwds)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
awx_1        | 18:58:54 uwsgi.1      |     return view_func(*args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/django/views/generic/base.py", line 68, in view
awx_1        | 18:58:54 uwsgi.1      |     return self.dispatch(request, *args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/api/generics.py", line 334, in dispatch
awx_1        | 18:58:54 uwsgi.1      |     return super(APIView, self).dispatch(request, *args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 494, in dispatch
awx_1        | 18:58:54 uwsgi.1      |     response = self.handle_exception(exc)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 454, in handle_exception
awx_1        | 18:58:54 uwsgi.1      |     self.raise_uncaught_exception(exc)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 491, in dispatch
awx_1        | 18:58:54 uwsgi.1      |     response = handler(request, *args, **kwargs)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/views.py", line 505, in options
awx_1        | 18:58:54 uwsgi.1      |     data = self.metadata_class().determine_metadata(request, self)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/api/metadata.py", line 198, in determine_metadata
awx_1        | 18:58:54 uwsgi.1      |     metadata = super(Metadata, self).determine_metadata(request, view)
awx_1        | 18:58:54 uwsgi.1      |   File "/venv/awx/lib64/python3.6/site-packages/rest_framework/metadata.py", line 69, in determine_metadata
awx_1        | 18:58:54 uwsgi.1      |     actions = self.determine_actions(request, view)
awx_1        | 18:58:54 uwsgi.1      |   File "./awx/api/metadata.py", line 256, in determine_actions
awx_1        | 18:58:54 uwsgi.1      |     for field in actions[method]:
awx_1        | 18:58:54 uwsgi.1      | RuntimeError: OrderedDict mutated during iteration
awx_1        | 18:58:54 uwsgi.1      | 172.18.0.1 OPTIONS /api/v2/instance_groups/1/instances/ - HTTP/1.1 500

# Fixed code
def determine_actions(self, request, view):
    actions = super(SublistAttachDetatchMetadata, self).determine_actions(request, view)
    method = "POST"
    if method in actions:
        for field in list(actions[method].keys()):
            if field == "id":
                continue
            actions[method].pop(field)
    return actions