Creating staff user using lms Django Administration panel doesn't create user profile object?

1,521 views
Skip to first unread message

Daniel McQuillen

unread,
Feb 23, 2016, 10:43:22 PM2/23/16
to General Open edX discussion
(Moved this post from operations, as it's more appropriate in this group...)

Seems like when you create a user with the Django admin panel the resulting user object isn't getting a profile object. 

I logged into the Django administration panel as a super user. I created a staff user, making sure to check "active" and "staff status" and gave the user a couple roles just for kicks. Staff status has help text that reads: "Designates whether the user can log into this admin site" so my assumption is this user should now be able to log into the Django admin panel.

However, when I try to log into the Django administration panel as this new user, I get a 500 error because Django can't find a 'profile' object for that user.

  ...

  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 189, in send

    response = receiver(signal=self, sender=sender, **named)

  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/models.py", line 1783, in enforce_single_login

    user.profile.set_login_session(key)

  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 483, in __get__

    self.related.get_accessor_name()

RelatedObjectDoesNotExist: User has no profile.


Interestingly, if I I create a staff user manually with the following steps, the user does get a profile:

sudo -u www-data /edx/bin/python.edxapp ./manage.py lms --settings aws create_user -s -p edx -e some_sta...@example.com
sudo -u www-data /edx/bin/python.edxapp ./manage.py lms --settings aws changepassword some_staff_member
sudo -u www-data /edx/bin/python.edxapp ./manage.py lms --settings aws shell

from django.contrib.auth.models import User
staff = User.objects.get(username="some_staff_member")
staff.is_staff = True staff.save()

I can log into the Django administration panel with this user without a problem.

Are there other operations you have to do on a user in the admin panel to give that new user a profile?

Braden MacDonald

unread,
Feb 25, 2016, 4:31:07 PM2/25/16
to edx-...@googlegroups.com
Hi Daniel,

I believe that creating users via the django admin is not meant to be supported, because the django admin code is not hooked into the other steps which are required, such as creating the Profile object and possibly sending an email to validate the email address.

However, you can create new users using the "create_user" command that you mentioned, or simply using the normal registration form on the site (which is going to be the most reliable way). Once the user is created properly, you can safely use either the django shell or the django admin to give the new user the "is_staff" global staff permission, if that's what you want to do.

Be aware: On Open edX, the "is_staff" permission has two effects:
  1. It grants access to the django admin site (this is the "normal" effect of this setting in django-land), though such users won't initially have permission to view any actual settings in the admin site without being granted them explicitly or given superuser status.
  2. It also grants access to all courses on the system in the LMS and Studio. This is an Open edX custom behavior.
Hope this helps.

--
Braden

--
You received this message because you are subscribed to the Google Groups "General Open edX discussion" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/edx-code/1e3f394c-846a-4585-9fb8-d8585c02804f%40googlegroups.com.

Daniel McQuillen

unread,
Feb 28, 2016, 6:52:32 PM2/28/16
to General Open edX discussion
Hi Branden,

Aha! Great, thanks for that. So based on what you said:
  • Creating both student and staff users should be done through UI or create_user command
  • Some functions -- or at the very least the create user function -- of the Django administration panel should not be used even though enabled. (I wonder what other functions are also problematic?)
This is probably a ridiculous question, but whenever I see "Instructor dashboard" in the docs, is that the same as the Django Administration panel?  I don't see a specific Django app dashboard meant for instructors. I do see the analytics one at port 18110 defined in main.yml -- although in setting up Fullstack I haven't been able to actually access anything at 18110...but that's another story :-) 

Braden MacDonald

unread,
Feb 28, 2016, 8:39:03 PM2/28/16
to edx-...@googlegroups.com
This is probably a ridiculous question, but whenever I see "Instructor dashboard" in the docs, is that the same as the Django Administration panel?

No. Go to any course in the LMS, and if you are staff in that course (or global staff), you will see a tab at the top called "Instructor" (alongside "Courseware", "Course Info", "Discussion", etc.). That is the instructor dashboard.

Inline image 2

--
You received this message because you are subscribed to the Google Groups "General Open edX discussion" group.

Daniel McQuillen

unread,
Feb 28, 2016, 9:52:14 PM2/28/16
to General Open edX discussion
Argh! So obvious! I kept thinking "Dashboard" implied a separate Django app. Completely missed that tab in the LMS view. Thanks for clarifying. :-)

wasim...@dfmail.org

unread,
Jul 12, 2018, 9:57:34 AM7/12/18
to General Open edX discussion
i am unable to create a new user from registration file in console it is showing 500 internal server error. Please let us know what needs to be done.
Reply all
Reply to author
Forward
0 new messages