Juniper.master - ecommerce.core.exceptions.MissingLmsUserIdException: Could not find lms_user_id

Hello,

i’m here about an error occured when i login to my Ecommerce Django Admin.
ecommerce2020-08-30 00_20_33-https___ecommerce.eduworld-cm.com_admin_ - Opera

Aug 29 16:30:42 lms [service_variant=ecommerce][django.request] ERROR [lms  26537] [/edx/app/ecommerce/venvs/ecommerce/lib/python3.5/site-packages/django/utils/log.py:228] - Internal Server Error: /jsi18n/
Traceback (most recent call last):
File "/edx/app/ecommerce/venvs/ecommerce/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/edx/app/ecommerce/venvs/ecommerce/lib/python3.5/site-packages/django/core/handlers/base.py", line 106, in _get_response
response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/edx/app/ecommerce/ecommerce/ecommerce/extensions/analytics/middleware.py", line 44, in process_view
user.add_lms_user_id('ecommerce_missing_lms_user_id_middleware', called_from)
File "/edx/app/ecommerce/ecommerce/ecommerce/core/models.py", line 608, in add_lms_user_id
raise MissingLmsUserIdException(error_msg)
ecommerce.core.exceptions.MissingLmsUserIdException: Could not find lms_user_id for user 2. Called from middleware with request path: /jsi18n/, referrer: https://ecommerce.eduworld-cm.com/admin/

After a couple of search, i found that with juniper we have to generate lms_user_id or allow this option to be ignored, according to this: https://openedx.atlassian.net/wiki/spaces/COMM/pages/940048716/Juniper

I dont exactly know how to do it:

1- Enabling the allow_missing_lms_user_id waffle switch : don’t clearly know how to do it :sweat:

2- The LMS user id can be back-filled for existing users by running the ecommerce/core/management/commands/import_user_ids.py management command : even running this command, how do i do it?

And, what is the good option, 1- enabling the waffle switch or 2- back-filled for existing users ?

Regards,

1 Like

I think you have only one option now to run the management command which back fills LMS user ids for existing users like this

sudo su ecommerce -s /bin/bash
cd ~/ecommerce
source ../ecommerce_env
python manage.py import_user_ids --settings=ecommerce.settings.production
2 Likes

@Zia.Fazal @Herve_siyou
I get this while running the last command :-

Any ideas?
Thanks!

You first need to export user ids from LMS into a temporary table temp_username_userid
See the details in the docstring of management command

1 Like

thanks @Zia_Fazal , I am confused here… Can you please explain which command i need to run on the ecommerce shell.
Thanks in advance.

@Natnael as @Zia_Fazal said, you need to load user_id in temp table:

  1. Create a file, and put this content inside ( for example: nano /tmp/import_user_ids.sql )

SELECT username, id as user_id FROM edxapp.auth_user INTO OUTFILE ‘/tmp/test_users2.csv’ FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘"’ LINES TERMINATED BY ‘\r\n’;

CREATE TABLE ecommerce.temp_username_userid(username VARCHAR(150),lms_user_id INT(11),PRIMARY KEY(lms_user_id)) ENGINE = InnoDB;

LOAD DATA LOCAL INFILE ‘/tmp/test_users2.csv’ INTO TABLE ecommerce.temp_username_userid FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘"’ LINES TERMINATED BY ‘\r\n’ (username, lms_user_id);

CREATE INDEX username_index ON ecommerce.temp_username_userid (username);

  1. Run those commands in the shell:

mysql -u root -p --enable-local-infile
mysql > source /tmp/import_user_ids.sql
mysql > exit

sudo su ecommerce -s /bin/bash
cd ~/ecommerce
source …/ecommerce_env

python manage.py import_user_ids --settings=ecommerce.settings.production
(if the one above failed, then try this one below)
python manage.py import_user_ids

exit

  1. Check the result:

mysql -u root -p

mysql> select id,username,lms_user_id from ecommerce.ecommerce_user;
±—±-----------------±------------+
| id | username | lms_user_id |
±—±-----------------±------------+
| 1 | ecommerce_worker | 1 |
| 2 | ecommerce_user_1 | null|
±—±-----------------±------------+
2 rows in set (0.00 sec)

You should see somthing like this…

  1. if “ecommerce_user_1” (this is the user i created in my case, so it can be different for you) has no “null” value, then:

mysql> update ecommerce.ecommerce_user set lms_user_id=1 where id=2;
mysql> select id,username,lms_user_id from ecommerce.ecommerce_user;
±—±-----------------±------------+
| id | username | lms_user_id |
±—±-----------------±------------+
| 1 | ecommerce_worker | 1 |
| 2 | ecommerce_user_1 | 1 |
±—±-----------------±------------+
2 rows in set (0.00 sec)
mysql> exit

3 Likes

@Herve_siyou Thank you very much ! This was very descriptive and easy to follow on. :+1:

1 Like

And may be, if it was an issue for you too…
In the oscar dashboard when I click on the Account button as you can see on the image, It gives me Server Error Page.

Humm, i never clicked on this link so i don’t know :sweat_smile: :sweat_smile: :sweat_smile:

Hey @Herve_siyou,
I confirm that we see the Server Error Page you mentioned above in our juniper and our former ironwood installation. however, I ignore it, since a couple of years ago. because there were no side effects for us. ( we accepted it to stay in place )
if you found a fixture, please let us know. and if it’s suffering you or your customers, don’t hesitate and follow it up with a new thread.
thank you