Fix stale Entra ID object ID not being repaired during user sync - #3360
Open
Lai Wei (weilai-irl) wants to merge 1 commit into
Open
Fix stale Entra ID object ID not being repaired during user sync#3360Lai 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
This PR fixes a regression in the Entra ID user sync flow where stale local_o365_objects.objectid values could no longer be detected and repaired after an Entra account was deleted/recreated, which in turn caused downstream enabled-status sync to keep re-suspending affected users.
Changes:
- Extends the existing bulk “existing users” SQL queries to also select the currently stored Entra object GUID (
obj.objectid AS o365objectid) alongside the local record id (obj.id AS objectid). - Updates the object ID repair logic in
sync_existing_user()to compare the stored GUID from the bulk query and issue a targeted update only when the GUID has actually changed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Lai Wei (weilai-irl)
force-pushed
the
wip-135632-m500
branch
from
August 6, 2026 12:00
ea130a6 to
164c6bc
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-m500
branch
from
August 6, 2026 13:22
164c6bc to
74f842d
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.