fix: don't throw ArgumentNullException on partial UpdateItem payloads (#17366)
BaseItemDto.Genres, .Tags, and .ProviderIds are plain auto-properties with
no default initializer, so they deserialize to null when a client omits
them from a partial POST /Items/{itemId} body. The OpenAPI spec documents
every BaseItemDto field as optional, but ItemUpdateController.UpdateItem
fed these three properties straight into Distinct()/Select()/ToList()
without a null check, so a request that (for example) only sets Tags
throws ArgumentNullException("source") once it reaches the unguarded
Genres line, before Tags is even processed.
Guard all three assignments with the same "if (request.X is not null)"
pattern already used for the neighboring Studios/Taglines/ProductionLocations
fields in this method, so omitted fields are left unchanged instead of
crashing the request.
Adds ItemUpdateControllerTests covering the reported repro (only Tags
supplied) and a companion case asserting existing Genres/ProviderIds are
preserved when omitted from the payload.
Signed-off-by: zerafachris <christopher.zerafa@blocklabs.io>
This commit is contained in:
@@ -250,7 +250,11 @@ public class ItemUpdateController : BaseJellyfinApiController
|
||||
item.IndexNumber = request.IndexNumber;
|
||||
item.ParentIndexNumber = request.ParentIndexNumber;
|
||||
item.Overview = request.Overview;
|
||||
item.Genres = request.Genres.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
|
||||
if (request.Genres is not null)
|
||||
{
|
||||
item.Genres = request.Genres.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
}
|
||||
|
||||
if (item is Episode episode)
|
||||
{
|
||||
@@ -293,10 +297,20 @@ public class ItemUpdateController : BaseJellyfinApiController
|
||||
item.CustomRating = request.CustomRating;
|
||||
|
||||
var currentTags = item.Tags;
|
||||
var newTags = request.Tags.Select(t => t.Trim()).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
var removedTags = currentTags.Except(newTags).ToList();
|
||||
var addedTags = newTags.Except(currentTags).ToList();
|
||||
item.Tags = newTags;
|
||||
List<string> removedTags;
|
||||
List<string> addedTags;
|
||||
if (request.Tags is not null)
|
||||
{
|
||||
var newTags = request.Tags.Select(t => t.Trim()).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
removedTags = currentTags.Except(newTags).ToList();
|
||||
addedTags = newTags.Except(currentTags).ToList();
|
||||
item.Tags = newTags;
|
||||
}
|
||||
else
|
||||
{
|
||||
removedTags = [];
|
||||
addedTags = [];
|
||||
}
|
||||
|
||||
if (item is Series rseries)
|
||||
{
|
||||
@@ -408,15 +422,18 @@ public class ItemUpdateController : BaseJellyfinApiController
|
||||
item.RunTimeTicks = request.RunTimeTicks;
|
||||
}
|
||||
|
||||
foreach (var pair in request.ProviderIds.ToList())
|
||||
if (request.ProviderIds is not null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pair.Value))
|
||||
foreach (var pair in request.ProviderIds.ToList())
|
||||
{
|
||||
request.ProviderIds.Remove(pair.Key);
|
||||
if (string.IsNullOrEmpty(pair.Value))
|
||||
{
|
||||
request.ProviderIds.Remove(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.ProviderIds = request.ProviderIds;
|
||||
item.ProviderIds = request.ProviderIds;
|
||||
}
|
||||
|
||||
if (item is Video video)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user