Cairn password reset

We have cairn running with the Tutor Wizard edition. I have created a user very long ago, but I forgot the password. Now I can’t figure out how to do a reset. What I’ve tried:

Re-running the createuser step (there seems to be no other helpful subcommand in the cairn binary)

I get this output:

tutor@staging:~$ tutor local run cairn-superset cairn createuser --admin maarten
docker-compose -f /home/tutor/.local/share/tutor/env/local/docker-compose.yml -f /home/tutor/.local/share/tutor/env/local/ -f /home/tutor/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local run --rm cairn-superset cairn createuser --admin maarten
Starting tutor_local_cairn-postgresql-permissions_1 ... done
Creating tutor_local_cairn-superset_run             ... done
Loaded your LOCAL configuration at [/app/]
logging was configured successfully
2022-09-07 09:14:29,738:INFO:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'>
Creating database reference for maarten
Creating user 'maarten'...
2022-09-07 09:15:11, adding new user to database. (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ab_user_email_key"
DETAIL:  Key (email)=( already exists.

[SQL: INSERT INTO ab_user (id, first_name, last_name, username, password, active, email, last_login, login_count, fail_login_count, created_on, changed_on, created_by_fk, changed_by_fk) VALUES (nextval('ab_user_id_seq'), %(first_name)s, %(last_name)s, %(username)s, %(password)s, %(active)s, %(email)s, %(last_login)s, %(login_count)s, %(fail_login_count)s, %(created_on)s, %(changed_on)s, %(created_by_fk)s, %(changed_by_fk)s) RETURNING]
[parameters: {'first_name': '', 'last_name': '', 'username': 'maarten', 'password': 'pbkdf2:sha256:150000$fXRKLcz0$28cb3713b60ec48b8e5ab7b3a70eaecc8de28da97233e847c6e5ee41eadb204b', 'active': True, 'email': '', 'last_login': None, 'login_count': None, 'fail_login_count': None, 'created_on': datetime.datetime(2022, 9, 7, 9, 15, 11, 718692), 'changed_on': datetime.datetime(2022, 9, 7, 9, 15, 11, 718721), 'created_by_fk': None, 'changed_by_fk': None}]
(Background on this error at:
Syncing maarten perms
Traceback (most recent call last):
  File "/scripts/cairn", line 286, in <module>
  File "/scripts/cairn", line 90, in main
  File "/scripts/cairn", line 144, in bootstrap_user
    if role in user.roles:
AttributeError: 'NoneType' object has no attribute 'roles'

I also don’t see a button in the login screen to reset my password, and there doesn’t seem to be a way for my colleague who can login to reset my password from within the interface either. What do I do?

Not a UI based operation, but you can accomplish this via the Django shell.

tutor dev run lms ./ lms shell

And following these instructions.

Thanks for the reply, that’s helpful as a workaround.

However, I would really expect that password reset would be included in a paid Tutor plugin. We’re planning on sharing Cairn credentials with people that run courses with us, so I would prefer not to have to enter the Django shell on production each time they forget their password.

By the way I’m also not sure if this would work. I think I’d have to go into the superset container rather than the lms container, right?

Ah, I misunderstood your need, my suggestion won’t help you. I’m not a tutor developer, so I’ll leave this to one of them.

Hi @MaartenGH,
Resetting a user password is indeed a feature of Cairn. The fact that the createuser script is crashing is a bug.

What version of Tutor and the Cairn plugin are you running?

$ tutor --version
tutor, version 14.0.5
$ cat ~/.local/lib/python3.7/site-packages/tutorcairn/ 
__version__ = "14.0.1"

Not sure how to check the cairn plugin version, but I guess this works.

The error seems to be due to the fact that you are attempting to create a user with a different username but with the same email address as an existing user. In other words, ‘’ is already present in the system but it is not associated to user “maarten”. Can you please check what is the correct username?

Of course, in such a scenario the script should not be crashing with an obscure error message. But if you confirm that this is the right diagnostic then I can work to improve the error management in that case.

I actually overwrote the database that I had this problem with the first time, but yes I can reproduce the issue as follows:

  1. tutor local run cairn-clickhouse cairn createuser maarten
  2. tutor local run cairn-superset cairn createuser --admin maarten
  3. tutor local run cairn-superset cairn createuser --admin maarten2

The third command leads to the same error.

Right. Command 3 confirms that the problem comes from the fact that the user already exists. I incorrectly assumed that the add_user command would fail if the user could not be created, as indicated by the “ adding new user to database.” message. Instead, the add_user command just returns False. I’ll add a check and release v14.0.2 now.