Cannot view audit logs when they contain entries with user id 0#19263
Merged
Cannot view audit logs when they contain entries with user id 0#19263
Conversation
581c275 to
2424d4a
Compare
2424d4a to
af9f130
Compare
lauraneto
commented
May 7, 2025
| private AuditLogResponseModel CreateAuditLogViewModel(IAuditItem auditItem) | ||
| { | ||
| Guid userKey = _userIdKeyResolver.GetAsync(auditItem.UserId).GetAwaiter().GetResult(); | ||
| IUser user = _userService.GetAsync(userKey).GetAwaiter().GetResult() |
Contributor
Author
There was a problem hiding this comment.
As the user service does no extra validations when retrieving the user, I removed this call entirely, as it seemed unnecessary as we only need the key.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates the audit log functionality to properly handle audit entries for the special Unknown/System user (user id 0).
- Updates the IUserIdKeyResolver documentation to indicate that an exception is thrown when a user is not found.
- Modifies the AuditLogPresentationFactory to return an empty user reference when the user id is the unknown/system user, avoiding an exception.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Umbraco.Core/Services/IUserIdKeyResolver.cs | Updated XML comments to document the new exception-based behavior when a user is not found. |
| src/Umbraco.Cms.Api.Management/Factories/AuditLogPresentationFactory.cs | Refactored audit log view model creation to handle user id 0 gracefully using a switch expression. |
1 task
This was referenced Jul 28, 2025
This was referenced Aug 26, 2025
This was referenced Sep 8, 2025
This was referenced Sep 8, 2025
This was referenced Oct 20, 2025
This was referenced Oct 27, 2025
This was referenced Mar 11, 2026
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.
Prerequisites
If there's an existing issue for this PR then this fixes #17149
Description
When using the
IContentServiceit is possible to pass in user id 0 (special Unknown/System user). This user does not actually exist in the database, and was therefore causing an exception to be thrown inIUserIdKeyResolver, which was called when mapping the audit logs.It was not mentioned in the reported issue, but when reproducing the issue I noticed it only happened with user 0, any other non-existing id would throw a foreign key error when trying to insert, so this was a special case.
Reproduction steps
In my case I added a simple API endpoint that I could easily call as needed, and added the following code. You can also check the reproduction sample provided in the issue.
Current behavior
The audit logs do not load and an error toast is shown.

New behavior
The audit logs load and show the entries with id 0 as Unknown.
