mozilla / network-pulse-api

API for the Network-Pulse project
Mozilla Public License 2.0
12 stars 22 forks source link

"Email Users" in the admin displays a 500 error when clicks #793

Closed danielfmiranda closed 2 years ago

danielfmiranda commented 2 years ago

When logged into the admin of the network pulse API, you currently cannot click into "email users" to view a list of different users on the app. Instead it displays a 500 error:

image

When taking a look at the logs in heroku, I can find this message whenever

image

Which is pretty much saying its returning an error because there is a user account with no profile linked to it.

My suggestion first step at this moment is to see if we can tap into the database using SQL and see how many user accounts do not have profiles linked to them, if its a spam account, we can remove it and this should solve the problem of not being able to look at the users.

We then need to figure out why a account without a profile got created in the first place

Pomax commented 2 years ago

I'd recommend first adding a try/except here, to restore functionality to the admin interface. E.g.

try:
    return intance.profile.created_at
except AttributeError:
  return 'Missing profile'
Pomax commented 2 years ago
full log capture ``` File "/app/pulseapi/users/admin.py", line 59, in account_created return instance.profile.created_at AttributeError: 'NoneType' object has no attribute 'created_at' at=info method=GET path="/admin/users/emailuser/" host=api.mozillapulse.org request_id=15165f13-587f-4c29-ac83-d226f1fc754e fwd="24.68.36.162" dyno=web.1 connect=0ms service=89ms status=500 bytes=551 protocol=https at=info method=GET path="/admin/users/emailuser/" host=api.mozillapulse.org request_id=d6955fa2-58b5-46b1-8d02-6baf91d6de3d fwd="24.68.36.162" dyno=web.1 connect=0ms service=85ms status=500 bytes=551 protocol=https Internal Server Error: /admin/users/emailuser/ Traceback (most recent call last): File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/options.py", line 565, in get_field return self.fields_map[field_name] KeyError: 'account_created' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/utils.py", line 262, in lookup_field f = _get_non_gfk_field(opts, name) File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/utils.py", line 293, in _get_non_gfk_field field = opts.get_field(name) File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/options.py", line 567, in get_field raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name)) django.core.exceptions.FieldDoesNotExist: EmailUser has no field named 'account_created' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 145, in _get_response response = self.process_exception_by_middleware(e, request) File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 143, in _get_response response = response.render() File "/app/.heroku/python/lib/python3.7/site-packages/django/template/response.py", line 106, in render self.content = self.rendered_content File "/app/.heroku/python/lib/python3.7/site-packages/django/template/response.py", line 83, in rendered_content content = template.render(context, self._request) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 171, in render return self._render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templatetags/base.py", line 33, in render return super().render(context) File "/app/.heroku/python/lib/python3.7/site-packages/django/template/library.py", line 214, in render _dict = self.func(*resolved_args, **resolved_kwargs) File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 339, in result_list 'results': list(results(cl)), File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 315, in results yield ResultList(None, items_for_result(cl, res, None)) File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 306, in __init__ super().__init__(*items) File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templatetags/admin_list.py", line 229, in items_for_result f, attr, value = lookup_field(field_name, result, cl.model_admin) File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/utils.py", line 271, in lookup_field value = attr(obj) File "/app/pulseapi/users/admin.py", line 59, in account_created return instance.profile.created_at AttributeError: 'NoneType' object has no attribute 'created_at' ```