Fix stale Entra ID object ID not being repaired during user sync - #3361
Open
Lai Wei (weilai-irl) wants to merge 1 commit into
Open
Fix stale Entra ID object ID not being repaired during user sync#3361Lai Wei (weilai-irl) wants to merge 1 commit into
Lai Wei (weilai-irl) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
Lai Wei (weilai-irl)
force-pushed
the
wip-135632-m501
branch
from
August 6, 2026 12:01
a372140 to
063154e
Compare
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.
Lai Wei (weilai-irl)
force-pushed
the
wip-135632-m501
branch
from
August 6, 2026 13:22
063154e to
b565c90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.