Fix/lti link issue from csv import#1110
Conversation
…king student number Users created via csv import did not populate the global_unique_identifier column in user table. If user logs in via LTI, lti_user unable to link to existing record in user table. It's also unable to create a new user record due to duplicate student number.
Greptile SummaryThis PR fixes a two-part bug where users imported via CSV with CAS/SAML type were created without
Confidence Score: 5/5Safe to merge; the fallback logic is guarded correctly and the root-cause fix prevents recurrence for all new CSV imports. The root-cause fix (setting global_unique_identifier at import time) is straightforward and correct. The LTI fallback guards the backfill with an explicit The Important Files Changed
Sequence DiagramsequenceDiagram
participant LTI as LTI Consumer
participant App as ComPAIR (lti_user.py)
participant DB as Database
LTI->>App: Login (global_unique_identifier, student_number)
App->>DB: Lookup User by global_unique_identifier
DB-->>App: None (user imported via CSV, no GUID set)
alt student_number provided
App->>DB: Lookup User by student_number
DB-->>App: existing_user (matched)
alt existing_user.global_unique_identifier is None
App->>DB: Backfill global_unique_identifier
end
App->>DB: Link LTIUser to existing_user
else no student_number or no match
App->>DB: Create new User
App->>DB: Link LTIUser to new User
end
App-->>LTI: Login successful
Reviews (2): Last reviewed commit: "Guard global_unique_identifier overwrite..." | Re-trigger Greptile |
Users imported via CSV classlist (CAS/SAML type) were created without global_unique_identifier populated. When these users later attempted to log in via LTI, two things could happen:
LTIUsercould not match the existing user byglobal_unique_identifier(it was NULL)student_number, attempting to create a new user record would fail with a database integrity error due to the unique constraint onstudent_numberThis resulted in an internal server error on LTI login.
Changes
classlist.py— Root cause fix. When importing users via CSV with CAS/SAML type, set global_unique_identifier to the CAS/SAML identifier at creation time. Prevents the problem for all future imports.lti_models/lti_user.py— Fallback for existing affected users. During LTI login, if a user cannot be matched by global_unique_identifier, attempt to match bystudent_number. If found, link the LTI user to the existing record and backfill global_unique_identifier.
tests/test_models.py— Adds a test case covering the fallback: a SAML user with a student_number but no global_unique_identifier is correctly linked when logging in via LTI, no duplicate user is created, and global_unique_identifier is backfilled.Notes
student_numberfallback.