Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add author or book because Sequence contains more than one matching element #2153

Open
1 task done
PearsonFlyer opened this issue Jan 25, 2023 · 14 comments
Open
1 task done
Labels
Status: Confirmed Stops stale bot from asking if stale Type: Bug Issue is a bug

Comments

@PearsonFlyer
Copy link
Collaborator

PearsonFlyer commented Jan 25, 2023

Is there an existing issue for this?

  • I have searched the existing open and closed issues

Current Behavior

When adding this author or by book, it's failing with a sequence error shown. This only happens on specific authors/books, and I think it's because the metadata has a clash that I can't determine.

https://api.bookinfo.club/v1/author/348641

https://api.bookinfo.club/v1/book/648086

Both of those throw a 503 in the trace logs, but both appear valid JSON in a browser.

Gist of logs: https://gist.github.com/PearsonFlyer/1b0ea60d637295ddfe3245ec156fa68a

Expected Behavior

Allow the addition of this book or author.

Steps To Reproduce

In Readarr (v0.1.2.1532 docker, and 0.1.2.1544 Windows)

Add edition:648086 or Agnes Savill and they return with "no results found", throwing the errors into logs.

Environment

- OS: Windows and Linux
- Readarr: 0.1.2.1532 (develop) and 0.1.2.1544 (nightly)
- Docker Install: Have tried both
- Using Reverse Proxy: Yes
- Browser: Firefox
- Database: Sqlite 3.36.0

What branch are you running?

Nightly

Trace Logs?

https://gist.github.com/PearsonFlyer/1b0ea60d637295ddfe3245ec156fa68a

AB#4803

@RudyBzhBzh
Copy link
Contributor

Hi,
Here is the reason why in the json retrieved with the provided link (https://api.bookinfo.club/v1/book/648086) :
Capture d’écran 2023-02-05 172116
The Works[1] ("Alexander...") has 2 Books ([3] & [7]) with the same ForeignId (648086).
One has not to be there, because it's not referencing his work with a "null" in ForeignWorkId. All Books in a work should have their ForeignWorkId equals to the ForeignId of the works.

Goodread themselves does not display the Books without link to the work.
Capture d’écran 2023-02-05 173212
As you'll see, there's only 9 Editions for this book, while json says 10 (Books[0] to Books[9]).

@rappo
Copy link

rappo commented Mar 5, 2023

I'm running into this same issue trying to add both J.D. Salinger and J.R.R. Tolkien, or any of their books.

I see you submitted a PR with a potential fix @RudyBzhBzh , thanks! How do we get someone to review it? 🤔

@bobokun
Copy link

bobokun commented Mar 20, 2023

I'm seeing the same issue with the book Inspired: How to Create Tech Products Customers Love (Silicon Valley Product Group) by Marty Cagan. Hopefully this fix will get merged soon :)

@RudyBzhBzh
Copy link
Contributor

I'm running into this same issue trying to add both J.D. Salinger and J.R.R. Tolkien, or any of their books.

I see you submitted a PR with a potential fix @RudyBzhBzh , thanks! How do we get someone to review it? 🤔

Don’t know 🤷‍♂️
I tell them on discord and @Qstick said:
Yea, this will be one that @ta264 needs to look at. He knows the metadata side of Readarr much better than I

@ta264
Copy link
Contributor

ta264 commented Mar 20, 2023

I'm not sure this is really the right fix, it's just covering up an upstream error that needs fixing there.

Some specific test cases (along with the Goodreads IDs for them) will help me narrow it down.

@RudyBzhBzh
Copy link
Contributor

RudyBzhBzh commented Mar 20, 2023

I'm not sure this is really the right fix, it's just covering up an upstream error that needs fixing there.

Some specific test cases (along with the Goodreads IDs for them) will help me narrow it down.

Of course, the error is somewhere else : goodreads or bookinfo… but I don’t think it’s something others can look at, right ?
if you have access to bookinfo (don’t know exactly how it works…), make an sql request to look for null foreignworkid… and you’ll have all the use cases you need ;)
As far as I know, all the books I mentioned in this PR here are now corrected « unfortunately », but this one should be taken as an exemple :
Inspired: How to Create Tech Products Customers Love (Silicon Valley Product Group) by Marty Cagan

also these ones I saw on discord :
JRR Tolkien and JD Salinger

And what « test case » do you want ?
The PR I propose is to exclude empty keys (which should not exists, I agree) throwing errors

Thanks.

@RudyBzhBzh
Copy link
Contributor

@ta264
Here is a test case (don't know if I correctly understood what you expect...) for Inspired: How to Create Tech Products Customers Love (Silicon Valley Product Group) by Marty Cagan
https://api.bookinfo.club/v1/author/1405323 :
Works[1] / Books [7] is same as Works[1] / Books [12], but 1st one has empty ForeignWorkID (throws errors), not last one.
Capture d’écran 2023-03-20 224222

@RudyBzhBzh
Copy link
Contributor

If you can make a SQL request to bookinfo, just try something like "select * from Books where ForeignWorkId is null"...

@RudyBzhBzh
Copy link
Contributor

I'm not sure this is really the right fix, it's just covering up an upstream error that needs fixing there.

Some specific test cases (along with the Goodreads IDs for them) will help me narrow it down.

Here are some more examples. I don't find any issue for JD Salinger... But there are 3 duplicates for Tolkien.
In the JSON file : https://api.bookinfo.club/v1/author/656983
Search for "ForeignWorkId":null => 3 results
For each result, look the ForeignId and search for it in the JSON (2 results for each => Duplicates throwing errors in readarr)

"ForeignId":30235419,"ForeignWorkId":50696770
"ForeignId":30235419,"ForeignWorkId":null

"ForeignId":58371246,"ForeignWorkId":91541368
"ForeignId":58371246,"ForeignWorkId":null

"ForeignId":34806310,"ForeignWorkId":95260436
"ForeignId":34806310,"ForeignWorkId":null

In a database point of view, "ForeignId is the "primary key" and must be unique (here we have duplicates...), whereas "ForeignWorkId is a "Foreign key" and must NOT be null, if it is, it means an orphan record... (no reference to a parent)

Hoppefully this will help.

My PR is not the best way to do, but I think it's working (at least to let time to others to dig for issues on infobook side...)

@RudyBzhBzh
Copy link
Contributor

@ta264 : Do I gave you enough elements to narrow it down ?

@bakerboy448 bakerboy448 added Status: Confirmed Stops stale bot from asking if stale and removed Status: Needs Triage New Issue needing triage labels Mar 31, 2023
@bakerboy448 bakerboy448 pinned this issue Mar 31, 2023
@ta264
Copy link
Contributor

ta264 commented Apr 14, 2023

I believe this has been fixed upstream and we are just waiting on all the caches to get refreshed (which could take a number of days). I'm reluctant to patch Readarr itself to work around it as then we wouldn't see that the upstream has issues.

@ta264
Copy link
Contributor

ta264 commented Apr 14, 2023

In particular the tolkien case should have been fixed up

@krin-san
Copy link

Running into a similar issue Sequence contains no matching with the "Меч князя Вячкі" (https://www.goodreads.com/book/show/28793329) book, author "Леанід Дайнека" (https://www.goodreads.com/author/show/14907415._):

Event log

Event title:

ReadarrErrorPipeline | Request Failed. POST /api/v1/book: Sequence contains no matching element

Message

Request Failed. POST /api/v1/book: Sequence contains no matching element

Exception

System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at NzbDrone.Core.Books.AddBookService.AddSkyhookData(Book newBook) in ./Readarr.Core/Books/Services/AddBookService.cs:line 128
   at NzbDrone.Core.Books.AddBookService.AddBook(Book book, Boolean doRefresh) in ./Readarr.Core/Books/Services/AddBookService.cs:line 47
   at Readarr.Api.V1.Books.BookController.AddBook(BookResource bookResource) in ./Readarr.Api.V1/Books/BookController.cs:line 157
   at lambda_method524(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Readarr.Http.Middleware.BufferingMiddleware.InvokeAsync(HttpContext context) in ./Readarr.Http/Middleware/BufferingMiddleware.cs:line 28
   at Readarr.Http.Middleware.IfModifiedMiddleware.InvokeAsync(HttpContext context) in ./Readarr.Http/Middleware/IfModifiedMiddleware.cs:line 41
   at Readarr.Http.Middleware.CacheHeaderMiddleware.InvokeAsync(HttpContext context) in ./Readarr.Http/Middleware/CacheHeaderMiddleware.cs:line 33
   at Readarr.Http.Middleware.StartingUpMiddleware.InvokeAsync(HttpContext context) in ./Readarr.Http/Middleware/StartingUpMiddleware.cs:line 38
   at Readarr.Http.Middleware.UrlBaseMiddleware.InvokeAsync(HttpContext context) in ./Readarr.Http/Middleware/UrlBaseMiddleware.cs:line 27
   at Readarr.Http.Middleware.VersionMiddleware.InvokeAsync(HttpContext context) in ./Readarr.Http/Middleware/VersionMiddleware.cs:line 29
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

@AndresPineros
Copy link

[Fatal] ReadarrErrorPipeline: Request Failed. POST /api/v1/book 

[v0.3.3.2171] System.InvalidOperationException: Sequence contains more than one matching element

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Confirmed Stops stale bot from asking if stale Type: Bug Issue is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants