Fixed: Edge case where import fails due to DB relationship mismatch

Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
Qstick
2020-09-06 22:40:17 -04:00
committed by nitsua
parent 2d28359627
commit ec0fc6f3e1
2 changed files with 14 additions and 15 deletions

View File

@@ -96,17 +96,8 @@ namespace NzbDrone.Core.Test.MediaFiles.BookImport.Specifications
[Test] [Test]
public void should_be_accepted_if_file_cannot_be_fetched() public void should_be_accepted_if_file_cannot_be_fetched()
{ {
_localTrack.Book = (Book)Builder<Book>.CreateListOfSize(1) _localTrack.Book = Builder<Book>.CreateNew()
.TheFirst(1) .With(e => e.BookFiles = new LazyLoaded<List<BookFile>>((List<BookFile>)null))
.With(e => e.Id = 1)
.With(e => e.BookFiles = new LazyLoaded<List<BookFile>>(
new List<BookFile>
{
new BookFile
{
Path = null
}
}))
.Build(); .Build();
Subject.IsSatisfiedBy(_localTrack, null).Accepted.Should().BeTrue(); Subject.IsSatisfiedBy(_localTrack, null).Accepted.Should().BeTrue();

View File

@@ -15,9 +15,9 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Specifications
_logger = logger; _logger = logger;
} }
public Decision IsSatisfiedBy(LocalBook item, DownloadClientItem downloadClientItem) public Decision IsSatisfiedBy(LocalBook localBook, DownloadClientItem downloadClientItem)
{ {
var bookFiles = item.Book?.BookFiles?.Value; var bookFiles = localBook.Book?.BookFiles?.Value;
if (bookFiles == null || !bookFiles.Any()) if (bookFiles == null || !bookFiles.Any())
{ {
@@ -27,9 +27,17 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Specifications
foreach (var bookFile in bookFiles) foreach (var bookFile in bookFiles)
{ {
if (bookFile.Size == item.Size) if (bookFile == null)
{ {
_logger.Debug("'{0}' Has the same filesize as existing file", item.Path); var book = localBook.Book;
_logger.Trace("Unable to get book file details from the DB. BookId: {0} BookFileId: {1}", book.Id, bookFile.Id);
return Decision.Accept();
}
if (bookFile.Size == localBook.Size)
{
_logger.Debug("'{0}' Has the same filesize as existing file", localBook.Path);
return Decision.Reject("Has the same filesize as existing file"); return Decision.Reject("Has the same filesize as existing file");
} }
} }