Handle user id 0 (Unknown/System) when building content version response#19361
Merged
Handle user id 0 (Unknown/System) when building content version response#19361
Conversation
…nse model `IUserIdKeyResolver.GetAsync` throws an exception when a user is not found. As user 0 does not really exist, the exception was being thrown. We now handle this scenario to return an empty reference.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates the document version response factory to correctly handle system/unknown users (ID 0) when building the API model.
- Refactors
CreateAsyncfrom an expression-bodied method to a block body - Adds a switch to return an empty
ReferenceByIdModelforConstants.Security.UnknownUserId - Cleans up formatting around entity key resolution calls
Comments suppressed due to low confidence (2)
src/Umbraco.Cms.Api.Management/Factories/DocumentVersionPresentationFactory.cs:33
- Avoid using
.Resultinside an async method as it can block threads; consider awaiting the asynchronousGetKeycall directly, e.g.await _entityService.GetKey(...).
new ReferenceByIdModel(_entityService.GetKey(contentVersion.ContentId, UmbracoObjectTypes.Document).Result),
src/Umbraco.Cms.Api.Management/Factories/DocumentVersionPresentationFactory.cs:27
- Add a unit test to cover the
UnknownUserIdbranch inCreateAsyncto verify that an emptyReferenceByIdModelis returned whencontentVersion.UserIdis 0.
Constants.Security.UnknownUserId => new ReferenceByIdModel(),
This was referenced Jul 28, 2025
This was referenced Aug 26, 2025
This was referenced Sep 8, 2025
This was referenced Oct 20, 2025
This was referenced Oct 27, 2025
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
This relates to issue #17149, as it was also being caused by having entries with user id 0.
Description
Details regarding the initial issue and how to test can be found in PR #19263.
In this case, instead of just opening the info tab, you will need to open the Rollback section.
The following code can be used to perform a publish with user id 0.
Before the fix
After the fix