Skip to content

Fix stale Entra ID object ID not being repaired during user sync - #3361

Open
Lai Wei (weilai-irl) wants to merge 1 commit into
MOODLE_501_STABLEfrom
wip-135632-m501
Open

Fix stale Entra ID object ID not being repaired during user sync#3361
Lai Wei (weilai-irl) wants to merge 1 commit into
MOODLE_501_STABLEfrom
wip-135632-m501

Conversation

@weilai-irl

Copy link
Copy Markdown
Collaborator

The N+1-avoidance refactor in usersync main.php replaced a direct per-user local_o365_objects lookup with a cache keyed by objectid, which only ever contains rows whose stored objectid is still active in Entra ID. This meant the object ID repair logic could never fire for users whose linked Entra account was deleted and recreated with a new object ID, leaving them permanently mismatched. The daily enabled-status sync task then kept re-suspending these accounts even after being manually re-enabled, since it also trusts the stale objectid.

Fix by selecting the currently stored objectid alongside the existing bulk user query (no extra query) and comparing it in memory, only issuing an UPDATE when it has actually changed.

Copilot AI lite review requested due to automatic review settings August 6, 2026 11:48
@weilai-irl Lai Wei (weilai-irl) self-assigned this Aug 6, 2026
@weilai-irl Lai Wei (weilai-irl) added this to the 2026-03 milestone Aug 6, 2026
@weilai-irl Lai Wei (weilai-irl) linked an issue Aug 6, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in the Entra ID user sync where stale local_o365_objects.objectid values (GUIDs) could not be repaired after an Entra account was deleted/recreated, causing downstream tasks to keep re-suspending users based on mismatched identities.

Changes:

  • Extends the bulk “existing users” SQL to also select the stored Entra GUID (obj.objectid) alongside the local object record ID (obj.id).
  • Reworks the object-id repair logic to compare/update using data already present in the bulk query (avoids relying on the objectid-keyed cache that excludes stale GUIDs).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread local/o365/classes/feature/usersync/main.php
The N+1-avoidance refactor in usersync main.php replaced a direct per-user local_o365_objects lookup with a cache keyed by objectid, which only ever contains rows whose stored objectid is still active in Entra ID. This meant the object ID repair logic could never fire for users whose linked Entra account was deleted and recreated with a new object ID, leaving them permanently mismatched. The daily enabled-status sync task then kept re-suspending these accounts even after being manually re-enabled, since it also trusts the stale objectid.

Fix by selecting the currently stored objectid alongside the existing bulk user query (no extra query) and comparing it in memory, only issuing an UPDATE when it has actually changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Moodle accounts connected to deleted Entra user objects

2 participants