# Buggy code
def exception_to_python(self, exc):
    """Convert serialized exception to Python exception."""
    if exc:
        if not isinstance(exc, BaseException):
            exc_module = exc.get("exc_module")
            if exc_module is None:
                cls = create_exception_cls(from_utf8(exc["exc_type"]), __name__)
            else:
                exc_module = from_utf8(exc_module)
                exc_type = from_utf8(exc["exc_type"])
                cls = getattr(sys.modules[exc_module], exc_type)
            exc_msg = exc["exc_message"]
            exc = cls(*exc_msg if isinstance(exc_msg, tuple) else exc_msg)
        if self.serializer in EXCEPTION_ABLE_CODECS:
            exc = get_pickled_exception(exc)
    return exc


# Traceback (KeyError)
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:      Traceback (most recent call last):
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/tornado/web.py", line 1541, in _execute
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          result = method(*self.path_args, **self.path_kwargs)
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/tornado/web.py", line 2949, in wrapper
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          return method(self, *args, **kwargs)
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/flower/api/tasks.py", line 314, in get
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          response = {'task-id': taskid, 'state': result.state}
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/result.py", line 471, in state
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          return self._get_task_meta()['status']
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/result.py", line 410, in _get_task_meta
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          return self._maybe_set_cache(self.backend.get_task_meta(self.id))
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/backends/base.py", line 359, in get_task_meta
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          meta = self._get_task_meta_for(task_id)
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/backends/base.py", line 674, in _get_task_meta_for
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          return self.decode_result(meta)
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/backends/base.py", line 278, in decode_result
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          return self.meta_from_decoded(self.decode(payload))
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/backends/base.py", line 274, in meta_from_decoded
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          meta['result'] = self.exception_to_python(meta['result'])
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:        File "/usr/local/lib/python3.5/dist-packages/celery/backends/base.py", line 252, in exception_to_python
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:          cls = getattr(sys.modules[exc_module], exc_type)
Jun 21 01:23:24 netdocker1-eastus2 daemon INFO 94e57cb12059[92630]:      KeyError: 'net_devices2.exceptions'

# Fixed code
def exception_to_python(self, exc):
    """Convert serialized exception to Python exception."""
    if exc:
        if not isinstance(exc, BaseException):
            exc_module = exc.get("exc_module")
            if exc_module is None:
                cls = create_exception_cls(from_utf8(exc["exc_type"]), __name__)
            else:
                exc_module = from_utf8(exc_module)
                exc_type = from_utf8(exc["exc_type"])
                try:
                    cls = getattr(sys.modules[exc_module], exc_type)
                except KeyError:
                    cls = create_exception_cls(exc_type, celery.exceptions.__name__)
            exc_msg = exc["exc_message"]
            exc = cls(*exc_msg if isinstance(exc_msg, tuple) else exc_msg)
        if self.serializer in EXCEPTION_ABLE_CODECS:
            exc = get_pickled_exception(exc)
    return exc