Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No UserPreferences created; logframe view crashes #22

Open
bitterjug opened this issue Jun 16, 2016 · 2 comments
Open

No UserPreferences created; logframe view crashes #22

bitterjug opened this issue Jun 16, 2016 · 2 comments

Comments

@bitterjug
Copy link
Contributor

I just did a new deploy:dev on master and, as there were no logframes (#21) I went over to /admin/logframe/logframe/ and created me one called test. Now I see it listed in the dashboard, but when I follow the link I get RelatedObjectDoesNotExist at /dashboard/test/.

Exception Value: User has no preferences.

You'd expect a user with no preferences would be easy to please.

Grepping for preferences in the source, I can't see anywhere where the preferences object gets created. Tests pass because the user object is mock.Mock()

And I suspect local user testing worked because a pre-existing user in the database got preferences added by the migration

But I can't see any code to create a preferences object for a new user.

Request Method: GET
Request URL: http://127.0.0.1:8000/dashboard/test/

Django Version: 1.8.13
Python Version: 2.7.11
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.humanize',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'rest_framework',
 'django_tables2',
 'jstemplate',
 'django_extensions',
 'django_assets',
 'floppyforms',
 'rest_framework_nested',
 'main',
 'logframe',
 'contacts',
 'dashboard',
 'appconf',
 'export')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/braces/views.py" in dispatch
  107.             request, *args, **kwargs)
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  89.         return handler(request, *args, **kwargs)
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/django/views/generic/base.py" in get
  158.         context = self.get_context_data(**kwargs)
File "/home/mark/workspace/kashana/django/website/logframe/mixins.py" in get_context_data
  80.         lf = self.get_logframe()
File "/home/mark/workspace/kashana/django/website/dashboard/mixins.py" in get_logframe
  27.         logframe = user.preferences.last_viewed_logframe
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/django/utils/functional.py" in inner
  226.         return func(self._wrapped, *args)
File "/home/mark/workspace/kashana/django/website/.ve/local/lib/python2.7/site-packages/django/db/models/fields/related.py" in __get__
  480.                     self.related.get_accessor_name()

Exception Type: RelatedObjectDoesNotExist at /dashboard/test/
Exception Value: User has no preferences.
@bitterjug
Copy link
Contributor Author

I think the fix should be to create the preferences when we try to access them, not when users are created, so as to be sure preferences are created transparently for existing users without them. Otherwise we have to trigger a save on each user to ensure they have a preferences instance. Maybe deploy along with another migration to make sure all existing users have preferences?

@daniell
Copy link
Contributor

daniell commented Jun 21, 2016

I've updated the fix to do the check when the 'preferences' property is accessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants