Fix stale Entra ID object ID not being repaired during user sync - #3359
Open
Lai Wei (weilai-irl) wants to merge 1 commit into
Open
Fix stale Entra ID object ID not being repaired during user sync#3359Lai 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 user sync flow where stale Entra ID object IDs could no longer be detected/repaired after an N+1-avoidance refactor, which in turn caused downstream tasks (like enabled-status sync) to keep acting on mismatched/stale identities.
Changes:
- Extend the bulk “existing user” SQL projections to also fetch the stored
local_o365_objects.objectidGUID alongside thelocal_o365_objects.id. - Update
sync_existing_user()to compare the stored GUID with the current Entra ID GUID and updatelocal_o365_objects.objectidwhen it differs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Lai Wei (weilai-irl)
force-pushed
the
wip-135632-m405
branch
from
August 6, 2026 12:00
0555726 to
dd346dd
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-m405
branch
from
August 6, 2026 13:22
dd346dd to
f3c94ce
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.