Login error after migrating from Native to Tutor

I have applied migration from native(hawthorn) to tutor(lilac) , data migration went well (mysql , mongodb and media) however once trying to login with existing user I am getting an error:

We couldn’t sign you in.

  • An error has occurred. Try refreshing the page, or check your Internet connection.

I have also created a new user using tutor command I also got the same error while trying to login.

Checked the lms error logs and found the following:

Attaching to tutor_local_lms_1
lms_1            |     response = self.process_exception_by_middleware(e, request)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
lms_1            |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
lms_1            |   File "/opt/pyenv/versions/3.8.6/lib/python3.8/contextlib.py", line 75, in inner
lms_1            |     return func(*args, **kwds)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
lms_1            |     return view_func(*args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view
lms_1            |     return self.dispatch(request, *args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 45, in _wrapper
lms_1            |     return bound_method(*args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
lms_1            |     return view(request, *args, **kwargs)
lms_1            |   File "./openedx/core/djangoapps/user_authn/views/login.py", line 617, in dispatch
lms_1            |     return super().dispatch(request, *args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
lms_1            |     response = self.handle_exception(exc)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
lms_1            |     self.raise_uncaught_exception(exc)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
lms_1            |     raise exc
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
lms_1            |     response = handler(request, *args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 45, in _wrapper
lms_1            |     return bound_method(*args, **kwargs)
lms_1            |   File "./openedx/core/lib/api/view_utils.py", line 393, in _wrapped
lms_1            |     return func(request)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 45, in _wrapper
lms_1            |     return bound_method(*args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
lms_1            |     response = view_func(request, *args, **kwargs)
lms_1            |   File "./openedx/core/djangoapps/user_authn/views/login.py", line 613, in post
lms_1            |     return login_user(request)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
lms_1            |     response = view_func(request, *args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/views/decorators/http.py", line 40, in inner
lms_1            |     return func(request, *args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/ratelimit/decorators.py", line 24, in _wrapped
lms_1            |     return fn(request, *args, **kw)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/ratelimit/decorators.py", line 24, in _wrapped
lms_1            |     return fn(request, *args, **kw)
lms_1            |   File "./openedx/core/djangoapps/user_authn/views/login.py", line 537, in login_user
lms_1            |     response = set_logged_in_cookies(request, response, possibly_authenticated_user)
lms_1            |   File "./openedx/core/djangoapps/user_authn/cookies.py", line 153, in set_logged_in_cookies
lms_1            |     _create_and_set_jwt_cookies(response, request, cookie_settings, user=user)
lms_1            |   File "./openedx/core/djangoapps/user_authn/cookies.py", line 290, in _create_and_set_jwt_cookies
lms_1            |     jwt = _create_jwt(request, user, expires_in)
lms_1            |   File "./openedx/core/djangoapps/user_authn/cookies.py", line 306, in _create_jwt
lms_1            |     access_token = create_dot_access_token(
lms_1            |   File "./openedx/core/djangoapps/oauth_dispatch/api.py", line 36, in create_dot_access_token
lms_1            |     return token_generator.create_token(request, refresh_token=True)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/tokens.py", line 341, in create_token
lms_1            |     self.request_validator.save_bearer_token(token, request)
lms_1            |   File "./openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py", line 84, in save_bearer_token
lms_1            |     super().save_bearer_token(token, request, *args, **kwargs)
lms_1            |   File "/opt/pyenv/versions/3.8.6/lib/python3.8/contextlib.py", line 75, in inner
lms_1            |     return func(*args, **kwds)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/oauth2_provider/oauth2_validators.py", line 544, in save_bearer_token
lms_1            |     access_token = self._create_access_token(
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/oauth2_provider/oauth2_validators.py", line 566, in _create_access_token
lms_1            |     return AccessToken.objects.create(
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
lms_1            |     return getattr(self.get_queryset(), name)(*args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 422, in create
lms_1            |     obj.save(force_insert=True, using=self.db)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 743, in save
lms_1            |     self.save_base(using=using, force_insert=force_insert,
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 780, in save_base
lms_1            |     updated = self._save_table(
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 873, in _save_table
lms_1            |     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 910, in _do_insert
lms_1            |     return manager._insert([self], fields=fields, return_id=update_pk,
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
lms_1            |     return getattr(self.get_queryset(), name)(*args, **kwargs)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1186, in _insert
lms_1            |     return query.get_compiler(using=using).execute_sql(return_id)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1377, in execute_sql
lms_1            |     cursor.execute(sql, params)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
lms_1            |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
lms_1            |     return executor(sql, params, many, context)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
lms_1            |     return self.cursor.execute(sql, params)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/utils.py", line 89, in __exit__
lms_1            |     raise dj_exc_value.with_traceback(traceback) from exc_value
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
lms_1            |     return self.cursor.execute(sql, params)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 71, in execute
lms_1            |     return self.cursor.execute(query, args)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
lms_1            |     res = self._query(query)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
lms_1            |     db.query(q)
lms_1            |   File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
lms_1            |     _mysql.connection.query(self, query)
lms_1            | django.db.utils.OperationalError: (1054, "Unknown column 'source_refresh_token_id' in 'field list'")

Did you try applying django migrations?

Yes the migrations were applied while running:

tutor local quickstart 

and they were successful, the problem is related to ‘source_refresh_token_id’ column as its in the error log:

"Unknown column 'source_refresh_token_id' in 'field list'"

I haven’t worked on either of these releases but from what I know about Django; this error means that the column source_refresh_token_id is not in the database.

Possible reasons:

  1. Migrations were not applied successfully. (We can rule this out since tutor local quickstart didn’t throw any error.)
  2. Django keeps a record of what migrations are already applied according to their file names. So it’s possible that you had some migration file in your Hawthorn setup that did not have source_refresh_token_id in it. Then you upgraded to Lilac and it had a migration file with the same name but with source_refresh_token_id in it. Now, Django knows that the migration file with this name was already applied so it won’t bother looking into it again and that column will never be created.

Looks like this column is probably to be migrated by oauth2_provider and the issue might have been caused due to an upgrade in that application.

This is the approach that I would use in such a case:

First, try running

./manage.py lms makemigrations && ./manage.py lms migrate

This should solve the problem and if it doesn’t…

You can create a migration file yourself to create the table and put it in a migrations folder and apply migrations. (I call it the Bandit’s way)

(This step is optional but I don’t like leaving traces when I do anything like this.) Delete the migration file and remove that file’s entry from the database. You can find that in the django_migrations table in your openedx database.

If you are not going to clean up after you are done, make sure you name your migration file in a way that it won’t clash with any other migration file Django might create in the future. You can use your name or your pet’s name or whatever. Just make sure it’s nowhere close to Django’s naming format for migration files.

These are solutions to the best of my knowledge but there may or may not be any other solution to this.

Hope this solves your problem, let me know if you need some more help. Best of luck.

@sagar thanks for your reply so I tried to run migrate again but it didn’t work, I did the following workaround I restored the MySQL backup once again and I have checked the database schema for tables related to user login I have found that there are difference between the hawthorn and lilac versions in the following tables:

  • oauth2_provider_refreshtoken

  • oauth2_provider_application

  • oauth2_provider_accesstoken

I added the missing columns in mysql and ran the migrations once again and everything worked fine.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.