[PR #4766] [MERGED] Bug in matching author of a book when this author already exists in the db. #4342

Closed
opened 2026-04-25 00:19:21 +02:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/advplyr/audiobookshelf/pull/4766
Author: @TN-SKYC
Created: 10/22/2025
Status: Merged
Merged: 12/21/2025
Merged by: @advplyr

Base: masterHead: Authors-bug


📝 Commits (4)

  • a5750de The key change: Move the Database.bookAuthorModel.create() block outside the if (!author) check,
  • 372c9a5 Increasing the timeout for bookfinder - some metadata providers heavily throttle the requests, original 10s is not enough.
  • 961d066 Wrong branch.
  • 076ece6 Auto-formatting

📊 Changes

1 file changed (+10 additions, -11 deletions)

View changed files

📝 server/scanner/Scanner.js (+10 -11)

📄 Description

Brief summary

I found a bug which causes the author field to remain empty when:

  • using a custom metadata provider
  • using "Match Books" action for a whole library
  • there is more than 1 book from the same author
  • author is identified and added to the db for the first book
  • next book is properly matched -> here we expect a full match, but the author field is not populated (remains empty)

Which issue is fixed?

I didn't find any reported issues, but initially the behavior seemed random and related to the custom provider.

In-depth Description

For a new author the current code goes through the whole if (!existingAuthor) and everything works fine. But when the autor is already in the db, then the

        await Database.bookAuthorModel
          .create({
            authorId: author.id,
            bookId: libraryItem.media.id
          })
          .then(() => {
            Logger.info(`[Scanner] quickMatchBookBuildUpdatePayload: Added author "${author.name}" to "${libraryItem.media.title}"`)
            libraryItem.media.authors.push(author)
            hasAuthorUpdates = true
          })

is not executed and author field remains empty.

How have you tested this?

Steps to reproduce:

  • configure custom metadata provider
  • create a new library in a new audiobookshelf instance (empty db!)
  • as a source, use a directory with at least 2 books from the same author (no metadata in .json, mp3 tags, etc.)
  • scan the library, then use "Match Books" option
    image

The result is that the first matched book (usually the last one when sorting by directory name) will have the author field populated. The next one will be missing an author. Other fields seem to work fine.

After the code change all the books get the author field populated correctly.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/advplyr/audiobookshelf/pull/4766 **Author:** [@TN-SKYC](https://github.com/TN-SKYC) **Created:** 10/22/2025 **Status:** ✅ Merged **Merged:** 12/21/2025 **Merged by:** [@advplyr](https://github.com/advplyr) **Base:** `master` ← **Head:** `Authors-bug` --- ### 📝 Commits (4) - [`a5750de`](https://github.com/advplyr/audiobookshelf/commit/a5750deaaf824e99fec54848640c21d5395dd626) The key change: Move the Database.bookAuthorModel.create() block outside the if (!author) check, - [`372c9a5`](https://github.com/advplyr/audiobookshelf/commit/372c9a5322bca988f66c4d714067bfa5a9922ac8) Increasing the timeout for bookfinder - some metadata providers heavily throttle the requests, original 10s is not enough. - [`961d066`](https://github.com/advplyr/audiobookshelf/commit/961d066bdd5d18efa2d8774362b2b236a8ca2d82) Wrong branch. - [`076ece6`](https://github.com/advplyr/audiobookshelf/commit/076ece6fe748fa4b0b44ea3c8e89cb940333781f) Auto-formatting ### 📊 Changes **1 file changed** (+10 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `server/scanner/Scanner.js` (+10 -11) </details> ### 📄 Description ## Brief summary I found a bug which causes the author field to remain empty when: - using a custom metadata provider - using "Match Books" action for a whole library - there is more than 1 book from the same author - author is identified and added to the db for the first book - next book is properly matched -> here we expect a full match, but the author field is not populated (remains empty) ## Which issue is fixed? I didn't find any reported issues, but initially the behavior seemed random and related to the custom provider. ## In-depth Description For a new author the current code goes through the whole `if (!existingAuthor)` and everything works fine. But when the autor is already in the db, then the await Database.bookAuthorModel .create({ authorId: author.id, bookId: libraryItem.media.id }) .then(() => { Logger.info(`[Scanner] quickMatchBookBuildUpdatePayload: Added author "${author.name}" to "${libraryItem.media.title}"`) libraryItem.media.authors.push(author) hasAuthorUpdates = true }) is not executed and author field remains empty. ## How have you tested this? Steps to reproduce: - configure custom metadata provider - create a new library in a new audiobookshelf instance (empty db!) - as a source, use a directory with at least 2 books from the same author (no metadata in .json, mp3 tags, etc.) - scan the library, then use "Match Books" option <img width="910" height="246" alt="image" src="https://github.com/user-attachments/assets/7e4a7f8b-c90f-4751-a5b5-76d0632914fb" /> The result is that the first matched book (usually the last one when sorting by directory name) will have the author field populated. The next one will be missing an author. Other fields seem to work fine. After the code change all the books get the author field populated correctly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-04-25 00:19:21 +02:00
adam closed this issue 2026-04-25 00:19:21 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#4342