Repository: fossasia/open-event-server

Issue:
On updating an order server returns internal server error for sending notifications
**Describe the bug**
Server returns internal server error when an order is updated. This error is thrown is sending notifications part.

**Expected behavior**
Error should not be thrown and notifications should be sent.

**Stacktrace**
```


INFO:werkzeug:127.0.0.1 - - [12/Jul/2018 02:55:37] "PATCH /v1/orders/4 HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/rs/Pradeep/github/open-event-server/app/__init__.py", line 66, in __call__
    return self.app(environ, start_response)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/rs/Pradeep/github/open-event-server/app/api/helpers/permissions.py", line 45, in decorator
    return fn(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 32, in wrapper
    return func(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 68, in dispatch_request
    response = method(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 56, in wrapper
    return func(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 307, in patch
    self._data_layer.update_object(obj, data, kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/data_layers/alchemy.py", line 144, in update_object
    self.after_update_object(obj, data, view_kwargs)
  File "/home/rs/Pradeep/github/open-event-server/app/api/orders.py", line 278, in after_update_object
    send_notif_ticket_cancel(order)
  File "/home/rs/Pradeep/github/open-event-server/app/api/helpers/notification.py", line 210, in send_notif_ticket_cancel
    title=NOTIFS[TICKET_CANCELLED]['title'].format(
KeyError: 'title'
```

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS]
 - Python Version [e.g. `3.5`, `3.6`]
 - `HEAD` Commit hash [e.g. `4629c62`]

**Additional context**
<!-- Add any other context about the problem here. -->



Discussion:
Can I fix this?

On Thu, Jul 12, 2018 at 3:06 AM, Pradeep Gangwar <notifications@github.com>
wrote:

> *Describe the bug*
> Server returns internal server error when an order is updated. This error
> is thrown is sending notifications part.
>
> *Expected behavior*
> Error should not be thrown and notifications should be sent.
>
> *Stacktrace*
>
>
>
> INFO:werkzeug:127.0.0.1 - - [12/Jul/2018 02:55:37] "PATCH /v1/orders/4 HTTP/1.1" 500 -
> Traceback (most recent call last):
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2309, in __call__
>     return self.wsgi_app(environ, start_response)
>   File "/home/rs/Pradeep/github/open-event-server/app/__init__.py", line 66, in __call__
>     return self.app(environ, start_response)
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2295, in wsgi_app
>     response = self.handle_exception(e)
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
>     return cors_after_request(app.make_response(f(*args, **kwargs)))
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
>     return cors_after_request(app.make_response(f(*args, **kwargs)))
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1741, in handle_exception
>     reraise(exc_type, exc_value, tb)
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
>     raise value
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
>     response = self.full_dispatch_request()
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
>     rv = self.handle_user_exception(e)
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
>     return cors_after_request(app.make_response(f(*args, **kwargs)))
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
>     return cors_after_request(app.make_response(f(*args, **kwargs)))
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
>     reraise(exc_type, exc_value, tb)
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
>     raise value
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
>     rv = self.dispatch_request()
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)
>   File "/home/rs/Pradeep/github/open-event-server/app/api/helpers/permissions.py", line 45, in decorator
>     return fn(*args, **kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 32, in wrapper
>     return func(*args, **kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/views.py", line 88, in view
>     return self.dispatch_request(*args, **kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 68, in dispatch_request
>     response = method(*args, **kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 56, in wrapper
>     return func(*args, **kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 307, in patch
>     self._data_layer.update_object(obj, data, kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/data_layers/alchemy.py", line 144, in update_object
>     self.after_update_object(obj, data, view_kwargs)
>   File "/home/rs/Pradeep/github/open-event-server/app/api/orders.py", line 278, in after_update_object
>     send_notif_ticket_cancel(order)
>   File "/home/rs/Pradeep/github/open-event-server/app/api/helpers/notification.py", line 210, in send_notif_ticket_cancel
>     title=NOTIFS[TICKET_CANCELLED]['title'].format(
> KeyError: 'title'
>
> *Additional details (please complete the following information):*
>
>    - OS: [e.g. MacOS, Ubuntu, CentOS]
>    - Python Version [e.g. 3.5, 3.6]
>    - HEAD Commit hash [e.g. 4629c62]
>
> *Additional context*
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-server/issues/5078>, or mute the
> thread
> <https://github.com/notifications/unsubscribe-auth/AVwOaNUA_wZrcr3BKbJBogBxRUHA10yKks5uFm_zgaJpZM4VL4tk>
> .
>


Resolving patch:
diff --git a/app/api/helpers/system_notifications.py b/app/api/helpers/system_notifications.py
--- a/app/api/helpers/system_notifications.py
+++ b/app/api/helpers/system_notifications.py
@@ -114,7 +114,7 @@
     },
     TICKET_CANCELLED: {
         'recipient': 'User',
-        'subject': u'Your order for {event_name} has been cancelled ({invoice_id})',
+        'title': u'Your order for {event_name} has been cancelled ({invoice_id})',
         'message': (
             u"Your order for {event_name} has been cancelled by the organizer"
             u"<br/>Please contact the organizer for more info" +
@@ -123,7 +123,7 @@
     },
     TICKET_CANCELLED_ORGANIZER: {
         'recipient': 'User',
-        'subject': u'Order ({invoice_id}) has been cancelled',
+        'title': u'Order ({invoice_id}) has been cancelled',
         'message': (
             u"Order ({invoice_id}) has been cancelled"
             u"<br/>Cancel Note: {cancel_note}."


Test patch: