# Buggy code
def update(self, event_id, service_id, data):
    data = self.validate(data, event_id, check_required=False)
    data_copy = data.copy()
    data_copy = self.fix_payload_post(event_id, data_copy)
    data = self._delete_fields(data)
    session = DataGetter.get_session(service_id)  # session before any updates are made
    obj = ServiceDAO.update(
        self, event_id, service_id, data, validate=False
    )  # session after update

    if "state" in data:
        if data["state"] == "pending" and session.state == "draft":
            trigger_new_session_notifications(session.id, event_id=event_id)

        if (data["state"] == "accepted" and session.state != "accepted") or (
            data["state"] == "rejected" and session.state != "rejected"
        ):
            trigger_session_state_change_notifications(
                obj, event_id=event_id, state=data["state"]
            )

    if session.start_time != obj.start_time or session.end_time != obj.end_time:
        trigger_session_schedule_change_notifications(obj, event_id)

    for f in ["track", "microlocation", "speakers", "session_type"]:
        if f in data_copy:
            setattr(obj, f, data_copy[f])
    obj = save_db_model(obj, SessionModel.__name__, event_id)
    return obj


# Traceback (KeyError)
[2016-07-28 00:35:59,077: ERROR/MainProcess] Received unregistered task of type 'import.event'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

The full contents of the message body was:
{'utc': True, 'chord': None, 'args': ('/home/aviaryan/github/open-event-orga-server/static/temp/event109.zip',), 'retries': 0, 'expires': None, 'task': 'import.event', 'callbacks': None, 'errbacks': None, 'timelimit': (None, None), 'taskset': None, 'kwargs': {'_flask_request_context': {'headers': {'Origin': u'http://localhost:5000', 'Content-Length': u'342747', 'Accept-Language': u'en-US,en;q=0.8', 'Accept-Encoding': u'gzip, deflate', 'Connection': u'keep-alive', 'Accept': u'*/*', 'User-Agent': u'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36', 'Host': u'localhost:5000', 'X-Requested-With': u'XMLHttpRequest', 'Cookie': u'_ga=GA1.1.135907395.1461594114;... (2240b)
Traceback (most recent call last):
File "/home/aviaryan/anaconda2/lib/python2.7/site-packages/celery/worker/consumer.py", line 456, in on_task_received
strategies[name](message, body,
KeyError: 'import.event'

# Fixed code
def update(self, event_id, service_id, data):
    data = self.validate(data, event_id, check_required=False)
    data_copy = data.copy()
    data_copy = self.fix_payload_post(event_id, data_copy)
    data = self._delete_fields(data)
    session = DataGetter.get_session(service_id)  # session before any updates are made
    obj = ServiceDAO.update(
        self, event_id, service_id, data, validate=False
    )  # session after update

    if "state" in data:
        if data["state"] == "pending" and session.state == "draft":
            trigger_new_session_notifications(session.id, event_id=event_id)

        if (data["state"] == "accepted" and session.state != "accepted") or (
            data["state"] == "rejected" and session.state != "rejected"
        ):
            trigger_session_state_change_notifications(
                obj, event_id=event_id, state=data["state"]
            )

    if session.start_time != obj.start_time or session.end_time != obj.end_time:
        trigger_session_schedule_change_notifications(obj, event_id)

    for f in ["track", "microlocation", "speakers", "session_type"]:
        if f in data_copy:
            setattr(obj, f, data_copy[f])
    obj = save_db_model(obj, SessionModel.__name__, event_id)
    return obj