[traceback] AttributeError: 'AnonymousUser' object has no attribute 'pk' in confirm_change_email



Users and Groups
5 years ago
5 years ago


(Reporter: willkg, Assigned: willkg)



Firefox Tracking Flags

(Not tracked)


(Whiteboard: u=user c=users p=1 s=2013.4)

Stacktrace (most recent call last):

  File "django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "django/views/decorators/http.py", line 41, in inner
    return func(request, *args, **kwargs)
  File "users/views.py", line 286, in confirm_change_email
    'username': u.username, 'duplicate': duplicate})
  File "jingo/__init__.py", line 75, in render
    rendered = render_to_string(request, template, context)
  File "jingo/__init__.py", line 93, in render_to_string
    return template.render(get_context())
  File "jingo/__init__.py", line 189, in render
    return super(Template, self).render(context_dict)
  File "jinja2/environment.py", line 891, in render
    return self.environment.handle_exception(exc_info, True)
  File "/data/www/support.mozilla.org/kitsune/apps/users/templates/users/change_email_complete.html", line 9, in top-level template code
    {% set crumbs = [(profile_url(user), user.username),
  File "users/helpers.py", line 17, in profile_url
    return reverse('users.profile', args=[user.pk])
  File "django/utils/functional.py", line 185, in inner
    return func(self._wrapped, *args)

AttributeError: 'AnonymousUser' object has no attribute 'pk'


This is worth looking at since it's related to creating new accounts and it's happened to a bunch of different email confirmation uuids.

Making this a P1 and tossing it in the current sprint to look at. I'll push it off if it looks benign-ish.
This has nothing to do with email templates (i.e. the stuff I changed a week or two ago), but is a total bug.

To test:

1. log in with some account
2. in Edit Profile, opt to change your email address
3. change it to something really clever like "ou812@example.com"
4. that'll print the confirm email link in the console
5. open up either a private window or a new instance of the browser with a different profile so you're guaranteed not to be logged in
6. copy and paste the confirm email link into the new window substituting appropriate things so it works locally

That kicks up the above stack trace.

PR: https://github.com/mozilla/kitsune/pull/1167
Also, comment #0 is wrong--this doesn't affect new accounts at all. It does affect people changing their email address. If they're not logged in, they get an error and it doesn't get changed.
Landed in https://github.com/mozilla/kitsune/commit/d39924ea01938bfa80d2ebd35c301ff45f7ae539

I'll wait to mark this FIXED after it goes to prod.
This ended up being a point.
Whiteboard: u=user c=users p= s=2013.4 → u=user c=users p=1 s=2013.4
Rehan just pushed this to prod. Pretty sure it's fixed now. I'll reopen if more issues pop up.
Last Resolved: 5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.