# Buggy code
def __init__(
    self,
    quantity=None,
    amount=None,
    address=None,
    city=None,
    state=None,
    country=None,
    zipcode=None,
    company=None,
    tax_business_info=None,
    transaction_id=None,
    paid_via=None,
    is_billing_enabled=False,
    created_at=datetime.datetime.now(datetime.timezone.utc),
    user_id=None,
    discount_code_id=None,
    event_id=None,
    status="pending",
    payment_mode=None,
    deleted_at=None,
    order_notes=None,
    tickets_pdf_url=None,
):
    self.identifier = get_new_order_identifier()
    self.quantity = quantity
    self.amount = amount
    self.city = city
    self.address = address
    self.state = state
    self.country = country
    self.zipcode = zipcode
    self.company = company
    self.tax_business_info = tax_business_info
    self.user_id = user_id
    self.event_id = event_id
    self.transaction_id = transaction_id
    self.paid_via = paid_via
    self.is_billing_enabled = is_billing_enabled
    self.created_at = created_at
    self.discount_code_id = discount_code_id
    self.status = status
    self.payment_mode = payment_mode
    self.deleted_at = deleted_at
    self.order_notes = order_notes
    self.tickets_pdf_url = tickets_pdf_url


# Traceback (KeyError)
Traceback (most recent call last):
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/sentry_sdk/integrations/flask.py", line 70, in sentry_patched_wsgi_app
environ, start_response
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/sentry_sdk/integrations/wsgi.py", line 120, in __call__
reraise(*_capture_exception(hub))
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/sentry_sdk/_compat.py", line 57, in reraise
raise value
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/sentry_sdk/integrations/wsgi.py", line 116, in __call__
_sentry_start_response, start_response, span
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/sentry_sdk/integrations/flask.py", line 69, in <lambda>
return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kush/open-event-server/app/__init__.py", line 80, in __call__
return self.app(environ, start_response)
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/kush/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/api.py", line 133, in decorated
return self.check_permissions(view, view_args, view_kwargs, *args, **kwargs)
File "/Users/kush/open-event-server/app/api/helpers/permission_manager.py", line 380, in permission_manager
return view(*view_args, **view_kwargs)
File "/Users/kush/open-event-server/app/api/helpers/permissions.py", line 46, in decorator
return fn(*args, **kwargs)
File "/Users/kush/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 32, in wrapper
return func(*args, **kwargs)
File "/Users/kush/open-event-server/venv/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/kush/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 68, in dispatch_request
response = method(*args, **kwargs)
File "/Users/kush/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 56, in wrapper
return func(*args, **kwargs)
File "/Users/kush/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 297, in patch
if json_data['data']['id'] != str(kwargs[self.data_layer.get('url_field', 'id')]):
KeyError: 'id'

# Fixed code
def __init__(
    self,
    quantity=None,
    amount=None,
    address=None,
    city=None,
    state=None,
    country=None,
    zipcode=None,
    company=None,
    tax_business_info=None,
    transaction_id=None,
    paid_via=None,
    is_billing_enabled=False,
    created_at=None,
    user_id=None,
    discount_code_id=None,
    event_id=None,
    status="pending",
    payment_mode=None,
    deleted_at=None,
    order_notes=None,
    tickets_pdf_url=None,
):
    self.identifier = get_new_order_identifier()
    self.quantity = quantity
    self.amount = amount
    self.city = city
    self.address = address
    self.state = state
    self.country = country
    self.zipcode = zipcode
    self.company = company
    self.tax_business_info = tax_business_info
    self.user_id = user_id
    self.event_id = event_id
    self.transaction_id = transaction_id
    self.paid_via = paid_via
    self.is_billing_enabled = is_billing_enabled
    if created_at is None:
        created_at = datetime.datetime.now(datetime.timezone.utc)
    self.created_at = created_at
    self.discount_code_id = discount_code_id
    self.status = status
    self.payment_mode = payment_mode
    self.deleted_at = deleted_at
    self.order_notes = order_notes
    self.tickets_pdf_url = tickets_pdf_url