diff --git a/src/NzbDrone.Core/Books/Services/BookService.cs b/src/NzbDrone.Core/Books/Services/BookService.cs index 5481bc97a..34a35e92d 100644 --- a/src/NzbDrone.Core/Books/Services/BookService.cs +++ b/src/NzbDrone.Core/Books/Services/BookService.cs @@ -63,6 +63,11 @@ namespace NzbDrone.Core.Books public Book AddBook(Book newBook, bool doRefresh = true) { + if (newBook.AuthorMetadataId == 0) + { + throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0"); + } + _bookRepository.Upsert(newBook); var editions = newBook.Editions.Value; @@ -244,6 +249,11 @@ namespace NzbDrone.Core.Books public void InsertMany(List books) { + if (books.Any(x => x.AuthorMetadataId == 0)) + { + throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0"); + } + _bookRepository.InsertMany(books); } diff --git a/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs b/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs index 8d12d3278..53af6e63e 100644 --- a/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs +++ b/src/NzbDrone.Core/MediaFiles/BookImport/ImportApprovedBooks.cs @@ -374,6 +374,12 @@ namespace NzbDrone.Core.MediaFiles.BookImport if (dbBook == null) { _logger.Debug($"Adding remote book {book}"); + + if (book.AuthorMetadataId == 0) + { + throw new InvalidOperationException("Cannot insert book with AuthorMetadataId = 0"); + } + try { book.Added = DateTime.UtcNow; diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs index 6f6eedc20..2604f15a2 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs @@ -747,6 +747,7 @@ namespace NzbDrone.Core.MetadataSource.Goodreads book.Author = author; book.AuthorMetadata = book.Author.Value.Metadata.Value; + book.AuthorMetadataId = author.AuthorMetadataId; book.CleanTitle = book.Title.CleanAuthorName(); } @@ -833,6 +834,7 @@ namespace NzbDrone.Core.MetadataSource.Goodreads book.Author = author; book.AuthorMetadata = book.Author.Value.Metadata.Value; + book.AuthorMetadataId = author.AuthorMetadataId; book.CleanTitle = book.Title.CleanAuthorName(); book.SeriesLinks = MapSearchSeries(resource.Title, resource.BookTitleBare);