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

NRE from TMDB Cast/Crew when a 'TMDB Person' does not yet exist #1202

Closed
fearnlj01 opened this issue Nov 18, 2024 · 3 comments
Closed

NRE from TMDB Cast/Crew when a 'TMDB Person' does not yet exist #1202

fearnlj01 opened this issue Nov 18, 2024 · 3 comments

Comments

@fearnlj01
Copy link
Contributor

fearnlj01 commented Nov 18, 2024

VERSION INFORMATION

Server Version: c24465c (current diff from master)

DESCRIPTION

Shoko.Server.Models.TMDB.TMDB_Crew & Shoko.Server.Models.TMDB.TMDB_Cast will both throw an exception if GetTmdbPerson is called but cannot find a corresponding person.

In turn, Shoko.Server.API.v3.Models.Common.Role is dependent upon these methods for the constructors taking TMDB data as a parameter, however does not account for the possibility of an exception being thrown.

In practice, this becomes an issue when using an endpoint such as /api/v3/Tmdb/Episode/{episodeID} with the option to retrieve Cast/Crew (as Shokofin does). If for whatever reason, there is something saved in TMDB_Episode_Cast, but no corresponding entries in the other TMDB tables the TMDB_Person table... a NRE occurs (which is currently a 'critical' issue in Shokofin's implementation, preventing the creation of a new library using the VFS).

I've got no idea how my database ended up in the state it has done... But updating TMDB show info via the currently available Web UI actions does not end up resolving the issue.

I can make a copy of my SQLite DB at time of writing this issue available upon request.

STEPS TO REPRODUCE

Using a copy of my DB... Making the following request:
GET http://localhost:8111/api/v3/TMDB/Episode/5101834?include=Titles,Overviews,Images,CrossReferences,Cast,Crew,FileCrossReferences

@Cazzar
Copy link
Member

Cazzar commented Nov 18, 2024

Are you able to provide logs & a stack trace so we can determine exactly where in the code it was happening?

@fearnlj01
Copy link
Contributor Author

The exception w/ call stack is as follows:

System.Exception: Unable to find TMDB Person with the given id. (Person=4942875)
   at Shoko.Server.Models.TMDB.TMDB_Cast.GetTmdbPerson() in G:\Shoko\Server\Shoko.Server\Models\TMDB\TMDB_Cast.cs:line 39
   at Shoko.Server.API.v3.Models.Common.Role..ctor(TMDB_Episode_Cast cast) in G:\Shoko\Server\Shoko.Server\API\v3\Models\Common\Role.cs:line 126
   at Shoko.Server.API.v3.Models.TMDB.Episode.<>c.<.ctor>b__85_0(TMDB_Episode_Cast cast) in G:\Shoko\Server\Shoko.Server\API\v3\Models\TMDB\Episode.cs:line 189
   at System.Linq.Enumerable.SelectListIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.SelectListIterator`2.ToList()
   at Shoko.Server.API.v3.Models.TMDB.Episode..ctor(TMDB_Show show, TMDB_Episode episode, TMDB_AlternateOrdering_Episode alternateOrderingEpisode, Nullable`1 includeDetails, IReadOnlySet`1 language) in G:\Shoko\Server\Shoko.Server\API\v3\Models\TMDB\Episode.cs:line 188
   at Shoko.Server.API.v3.Models.TMDB.Episode..ctor(TMDB_Show show, TMDB_Episode episode, Nullable`1 includeDetails, IReadOnlySet`1 language) in G:\Shoko\Server\Shoko.Server\API\v3\Models\TMDB\Episode.cs:line 139
   at Shoko.Server.API.v3.Controllers.TmdbController.GetTmdbEpisodeByEpisodeID(Int32 episodeID, HashSet`1 include, HashSet`1 language, String alternateOrderingID) in G:\Shoko\Server\Shoko.Server\API\v3\Controllers\TmdbController.cs:line 2002
   at lambda_method893(Closure, Object, Object[])
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)

Trying to find any other logs related to this person id in the past month... I can only find logs that match the below.

[2024-10-20 11:29:54:908] Debug|Shoko.Server.Providers.TMDB.TmdbMetadataService > Acquiring lock 'metadata & images' for Person 4942875. (Reason: Purge)
[2024-10-20 11:29:54:908] Debug|Shoko.Server.Providers.TMDB.TmdbMetadataService > Acquired lock 'metadata & images' for Person 4942875. (Reason: Purge)
[2024-10-20 11:29:54:908] Debug|Shoko.Server.Providers.TMDB.TmdbMetadataService > Released lock 'metadata & images' for Person 4942875 after 00:00:00.0102520. (Reason: Purge)

Looking again at my db, it appears my previous comments on there being no corresponding entries is not correct. I was attempting to find the TMDB IDs in the Shoko assigned ID column... In this case, it's only the lack of a corresponding TMDB_Person record which ultimately causes the issue.

@fearnlj01
Copy link
Contributor Author

As extra information... If all data for a TMDB show is explicitly purged (DELETE /api/v3/Tmdb/Show/{showID}), then refreshed (POST /api/v3/Tmdb/Show/{showID}/Action/Refresh), this seems to leave the database in the expected operational state.

Given that only the TMDB Person ID is presented when the exception is thrown, you'd have to either attach a debugger or go to the database to work out which show ID it is that needs fixing.

A quick search of my logs indicate that I've had this error occur for 111 unique different person IDs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants