Skip to content

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

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

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

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:49
@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 user sync refactor where stale Entra ID GUIDs could not be repaired (because cached lookups were keyed only by currently-active object IDs), leaving users permanently mismatched and repeatedly re-suspended by downstream status sync.

Changes:

  • Extends existing bulk “existing users” queries to also select the stored Entra GUID (obj.objectid AS o365objectid) alongside the local object row id.
  • Repairs the stored Entra GUID using in-memory comparison (no additional per-user lookup), issuing an UPDATE only when the GUID has changed.

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

Comment thread local/o365/classes/feature/usersync/main.php Outdated
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