Repository: fossasia/open-event-server

Issue:
EncodeError: Object of type User is not JSON serializable
Sentry Issue: [EVENTYAY-SERVER-P](https://sentry.fossasia.org/organizations/eventyay/issues/225/?referrer=github_integration)

```
TypeError: Object of type User is not JSON serializable
(3 additional frame(s) were not displayed)
...
  File "__init__.py", line 412, in dumps
    **kw).encode(obj)
  File "simplejson/encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "simplejson/encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "kombu/utils/json.py", line 59, in default
    return super(JSONEncoder, self).default(o)
  File "simplejson/encoder.py", line 273, in default
    o.__class__.__name__)

EncodeError: Object of type User is not JSON serializable
(31 additional frame(s) were not displayed)
...
  File "__init__.py", line 412, in dumps
    **kw).encode(obj)
  File "simplejson/encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "simplejson/encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "kombu/utils/json.py", line 59, in default
    return super(JSONEncoder, self).default(o)
  File "simplejson/encoder.py", line 273, in default
    o.__class__.__name__)
```


Discussion:

Resolving patch:
diff --git a/app/api/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -344,7 +344,7 @@ def reset_password_post():
         link = make_frontend_url('/reset-password', {'token': user.reset_password})
         if user.was_registered_with_order:
             send_email(
-                to=user,
+                to=user.email,
                 action=PASSWORD_RESET_AND_VERIFY,
                 subject=MAILS[PASSWORD_RESET_AND_VERIFY]['subject'].format(
                     app_name=get_settings()['app_name']
@@ -354,7 +354,7 @@ def reset_password_post():
 
         else:
             send_email(
-                to=user,
+                to=user.email,
                 action=PASSWORD_RESET,
                 subject=MAILS[PASSWORD_RESET]['subject'].format(
                     app_name=get_settings()['app_name']
@@ -423,7 +423,7 @@ def change_password():
             user.password = new_password
             save_to_db(user)
             send_email(
-                to=user,
+                to=user.email,
                 action=PASSWORD_CHANGE,
                 subject=MAILS[PASSWORD_CHANGE]['subject'].format(
                     app_name=get_settings()['app_name']
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -59,6 +59,10 @@ def send_email(to, action, subject, html, attachments=None, bcc=None):
     """
     from .tasks import get_smtp_config, send_email_task_sendgrid, send_email_task_smtp
 
+    if isinstance(to, User):
+        logger.warning('to argument should be an email string, not a User object')
+        to = to.email
+
     if string_empty(to):
         logger.warning('Recipient cannot be empty')
         return False
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -95,7 +95,7 @@ def after_create_object(self, user, data, view_kwargs):
         link = make_frontend_url('/verify', {'token': hash})
         settings = get_settings()
         send_email(
-            to=user,
+            to=user.email,
             action=USER_REGISTER,
             subject=MAILS[USER_REGISTER]['subject'].format(app_name=settings['app_name']),
             html=render_template(


Test patch: