# Buggy code
def after_create_object(self, order, data, view_kwargs):
    """
    after create object method for OrderListPost Class
    :param order:
    :param data:
    :param view_kwargs:
    :return:
    """
    order_tickets = {}
    for holder in order.ticket_holders:
        if holder.id != current_user.id:
            pdf = create_save_pdf(
                render_template("/pdf/ticket_attendee.html", order=order, holder=holder)
            )
        else:
            pdf = create_save_pdf(
                render_template("/pdf/ticket_purchaser.html", order=order)
            )
        holder.pdf_url = pdf
        save_to_db(holder)
        if not order_tickets.get(holder.ticket_id):
            order_tickets[holder.ticket_id] = 1
        else:
            order_tickets[holder.ticket_id] += 1
    for ticket in order_tickets:
        od = OrderTicket(
            order_id=order.id, ticket_id=ticket, quantity=order_tickets[ticket]
        )
        save_to_db(od)
    order.quantity = order.get_tickets_count()
    save_to_db(order)
    if not has_access("is_coorganizer", event_id=data["event"]):
        TicketingManager.calculate_update_amount(order)
    send_email_to_attendees(order, current_user.id)
    send_notif_to_attendees(order, current_user.id)

    order_url = make_frontend_url(
        path="/orders/{identifier}".format(identifier=order.identifier)
    )
    for organizer in order.event.organizers:
        send_notif_ticket_purchase_organizer(
            organizer, order.invoice_number, order_url, order.event.name
        )

    data["user_id"] = current_user.id


# Traceback (KeyError)
Exception on /v1/orders/fe5a8c1d-ac6d-4bd3-ac4b-0540d4bcc03b/attendees [GET]
Traceback (most recent call last):
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/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 145, in get
objects_count, objects = self._data_layer.get_collection(qs, kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/src/flask-rest-jsonapi/flask_rest_jsonapi/data_layers/alchemy.py", line 92, in get_collection
query = self.query(view_kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/attendees.py", line 81, in query
id=order.user_id):
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/helpers/permission_manager.py", line 445, in has_access
auth = permissions[access_level](lambda *a, **b: True, (), {}, (), **kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/helpers/permissions.py", line 45, in decorator
return fn(*args, **kwargs)
File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/helpers/permission_manager.py", line 109, in is_user_itself
if not user.is_admin and not user.is_super_admin and user.id != kwargs['user_id']:
KeyError: 'user_id'

# Fixed code
def after_create_object(self, order, data, view_kwargs):
    """
    after create object method for OrderListPost Class
    :param order:
    :param data:
    :param view_kwargs:
    :return:
    """
    order_tickets = {}
    for holder in order.ticket_holders:
        if holder.id != current_user.id:
            pdf = create_save_pdf(
                render_template("/pdf/ticket_attendee.html", order=order, holder=holder)
            )
        else:
            pdf = create_save_pdf(
                render_template("/pdf/ticket_purchaser.html", order=order)
            )
        holder.pdf_url = pdf
        save_to_db(holder)
        if not order_tickets.get(holder.ticket_id):
            order_tickets[holder.ticket_id] = 1
        else:
            order_tickets[holder.ticket_id] += 1
    for ticket in order_tickets:
        od = OrderTicket(
            order_id=order.id, ticket_id=ticket, quantity=order_tickets[ticket]
        )
        save_to_db(od)
    order.quantity = order.get_tickets_count()
    order.user = current_user
    save_to_db(order)
    if not has_access("is_coorganizer", event_id=data["event"]):
        TicketingManager.calculate_update_amount(order)
    send_email_to_attendees(order, current_user.id)
    send_notif_to_attendees(order, current_user.id)

    order_url = make_frontend_url(
        path="/orders/{identifier}".format(identifier=order.identifier)
    )
    for organizer in order.event.organizers:
        send_notif_ticket_purchase_organizer(
            organizer, order.invoice_number, order_url, order.event.name
        )

    data["user_id"] = current_user.id