# Buggy code
def before_post(self, args, kwargs, data):
    """
    before post method to check for required relationship and proper permission
    :param args:
    :param kwargs:
    :param data:
    :return:
    """
    require_relationship(["event"], data)
    if not has_access("is_coorganizer", event_id=data["event"]):
        raise ObjectNotFound(
            {"parameter": "event_id"}, "Event: {} not found".format(data["event_id"])
        )

    if (
        get_count(
            db.session.query(Ticket.id).filter_by(
                name=data["name"], event_id=int(data["event"]), deleted_at=None
            )
        )
        > 0
    ):
        raise ConflictException(
            {"pointer": "/data/attributes/name"}, "Ticket already exists"
        )

    if (
        get_count(
            db.session.query(Event).filter_by(
                id=int(data["event"]), is_ticketing_enabled=False
            )
        )
        > 0
    ):
        raise MethodNotAllowed(
            {"parameter": "event_id"}, "Ticketing is disabled for this Event"
        )


# Traceback (KeyError)
Traceback (most recent call last):
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/__init__.py", line 66, in __call__
return self.app(environ, start_response)
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 32, in wrapper
return func(*args, **kwargs)
File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/views.py", line 88, in view
return self.dispatch_request(*args, **kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 68, in dispatch_request
response = method(*args, **kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 56, in wrapper
return func(*args, **kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 202, in post
self.before_post(args, kwargs, data=data)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/tickets.py", line 37, in before_post
"Event: {} not found".format(data['event_id']))
KeyError: 'event_id'

# Fixed code
def before_post(self, args, kwargs, data):
    """
    before post method to check for required relationship and proper permission
    :param args:
    :param kwargs:
    :param data:
    :return:
    """
    require_relationship(["event"], data)
    if not has_access("is_coorganizer", event_id=data["event"]):
        raise ObjectNotFound(
            {"parameter": "event_id"}, "Event: {} not found".format(data["event"])
        )

    if (
        get_count(
            db.session.query(Ticket.id).filter_by(
                name=data["name"], event_id=int(data["event"]), deleted_at=None
            )
        )
        > 0
    ):
        raise ConflictException(
            {"pointer": "/data/attributes/name"}, "Ticket already exists"
        )

    if (
        get_count(
            db.session.query(Event).filter_by(
                id=int(data["event"]), is_ticketing_enabled=False
            )
        )
        > 0
    ):
        raise MethodNotAllowed(
            {"parameter": "event_id"}, "Ticketing is disabled for this Event"
        )