From 33bb5960e55289f47cf5469e074866405ba7e28e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 18 Jul 2022 22:31:49 +0100 Subject: [PATCH] Fixed: Null reference error when import list adds new album to existing artist (cherry picked from commit 5e3045db86748d0ab407a6785007cb6bbd4f46a6) --- .../ImportListTests/ImportListSyncServiceFixture.cs | 5 +++-- src/NzbDrone.Core/ImportLists/ImportListSyncService.cs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs b/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs index 58cea4fe7..9718e914d 100644 --- a/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs +++ b/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs @@ -89,14 +89,14 @@ namespace NzbDrone.Core.Test.ImportListTests { Mocker.GetMock() .Setup(v => v.FindById(_importListReports.First().ArtistMusicBrainzId)) - .Returns(new Artist { ForeignArtistId = _importListReports.First().ArtistMusicBrainzId }); + .Returns(new Artist { Id = 1, ForeignArtistId = _importListReports.First().ArtistMusicBrainzId }); } private void WithExistingAlbum() { Mocker.GetMock() .Setup(v => v.FindById(_importListReports.First().AlbumMusicBrainzId)) - .Returns(new Album { ForeignAlbumId = _importListReports.First().AlbumMusicBrainzId }); + .Returns(new Album { Id = 1, ForeignAlbumId = _importListReports.First().AlbumMusicBrainzId }); } private void WithExcludedArtist() @@ -215,6 +215,7 @@ namespace NzbDrone.Core.Test.ImportListTests public void should_add_if_existing_artist_but_new_album() { WithAlbumId(); + WithArtistId(); WithExistingArtist(); Subject.Execute(new ImportListSyncCommand()); diff --git a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs index b8eca4c3c..0f099a14e 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using NLog; using NzbDrone.Common.Extensions; @@ -243,8 +244,9 @@ namespace NzbDrone.Core.ImportLists } }; - if (importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum) + if (importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum && toAddArtist.AddOptions != null) { + Debug.Assert(toAddArtist.Id == 0, "new artist added but ID is not 0"); toAddArtist.AddOptions.AlbumsToMonitor.Add(toAdd.ForeignAlbumId); }