Fix stale Entra ID object ID not being repaired during user sync - #3362
Open
Lai Wei (weilai-irl) wants to merge 1 commit into
Open
Fix stale Entra ID object ID not being repaired during user sync#3362Lai 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 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.
Lai Wei (weilai-irl)
force-pushed
the
wip-135632-m502
branch
from
August 6, 2026 12:01
31d0a72 to
0c82404
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-m502
branch
from
August 6, 2026 13:23
0c82404 to
899f426
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.