Kareadita / Kavita

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
http://www.kavitareader.com
GNU General Public License v3.0
5.89k stars 300 forks source link

Possible bug parsing CBL files in version 8.2.0 #3054

Closed dacmcbibs closed 3 weeks ago

dacmcbibs commented 1 month ago

What happened?

CBL importing doesn't make it passed the first validate step image

What did you expect?

To be able to import CBL files

Kavita Version Number - If you don not see your version number listed, please update Kavita and see if your issue still persists.

0.8.1 - Stable

What operating system is Kavita being hosted from?

Docker (LSIO Container)

If the issue is being seen on Desktop, what OS are you running where you see the issue?

None

If the issue is being seen in the UI, what browsers are you seeing the problem on?

Chrome, Microsoft Edge

If the issue is being seen on Mobile, what OS are you running where you see the issue?

None

If the issue is being seen on the Mobile UI, what browsers are you seeing the problem on?

No response

Relevant log output

Logs and database with the issue have been shared on Discord

Additional Notes

After reviewing the SQL query that occurs during the import the issue appears to be with normalized names not being correctly generated for comics in a Comic Vine library. Discussed on Discord with majora2007 (Joe) and DacMcbibs

majora2007 commented 1 month ago

I confirmed that there should be a match by inspecting the DB. This requires looking at the code to validate if a bug or not.

Cducharme84 commented 1 month ago

I can replicate this, I have multiple CBLs I contributed to the repo (just tested with "Space Goat Evil Dead" and "Friday the 13th") both tested tonight have been imported before and I have confirmed all series are present with proper CV tagging. Getting the same result of no access to any series, user importing does have access to the whole gamut of libraries.

I thought to test ones I knew were working tonight as Discord user cwar in this message mentioned the behavior started happening after changing to the CV library type.

I tested with a test library containing all the Friday the 13th series and set it as Comic which allowed import so this does seem to be exclusive to the CV library type.

Jmatt110 commented 1 month ago

Also having this same issue. Library is CV type, definitely have all issues in the CBL. Running version 0.8.2.0 of Kavita on Windows.

image

cwar commented 1 month ago

Hi there, I am the user that mentioned that @Cducharme84 mentioned had the issue as well. I have an idea what the problem seems to be, but I'm not sure what's the best way of going to fix it. I also haven't built or worked with dotnet in a very long time and I'm having a bit of trouble getting my environment going.

Since I've converted my library to Type: Comic Vine I can see that both the NormalizedLocalizedName and NormalizedName field of the Series table now has the year appended to the name. In the previous library (Type: Comic) there was not a year appended to the name. (Note: The Name field of the Series record also has the year added to it, but the relevant query looks at NormalizedLocalizedName and NormalizedName).

Also, I noticed that the query that gets executed when the CBL file is validated does not have the year appended to the name.

For example, running this on a backup DB: image vs the Type: Comic Vine DB: image

And the trace query that runs when the validate job executes:

[Kavita] [2024-07-23 01:19:38.556 +00:00  62] [Information] Microsoft.EntityFrameworkCore.Database.Command Executed DbCommand (3ms) [Parameters=[@__normalizedNames_0='["batman","thebatmanchronicles","legendsofthedarkknight","catwoman","batmanthemonstermen","batmanthemadmonk","batmanthemanwholaughs","batmanjourneyintoknight","batmanconfidential","batmanshadowofthebatannual","batmanlegendsofthedarkknightannual","batmanannual","detectivecomicsannual","batmantenses"]' (Size = 300), @__userId_1='1'], CommandType='"Text"', CommandTimeout='30']
SELECT "s"."Id", "s"."AvgHoursToRead", "s"."CoverImage", "s"."CoverImageLocked", "s"."Created", "s"."CreatedUtc", "s"."FolderPath", "s"."Format", "s"."LastChapterAdded", "s"."LastChapterAddedUtc", "s"."LastFolderScanned", "s"."LastFolderScannedUtc", "s"."LastModified", "s"."LastModifiedUtc", "s"."LibraryId", "s"."LocalizedName", "s"."LocalizedNameLocked", "s"."LowestFolderPath", "s"."MaxHoursToRead", "s"."MinHoursToRead", "s"."Name", "s"."NormalizedLocalizedName", "s"."NormalizedName", "s"."OriginalName", "s"."Pages", "s"."SortName", "s"."SortNameLocked", "s"."WordCount"
FROM "Series" AS "s"
WHERE ("s"."NormalizedName" IN (
    SELECT "n"."value"
    FROM json_each(@__normalizedNames_0) AS "n"
) OR "s"."NormalizedLocalizedName" IN (
    SELECT "n0"."value"
    FROM json_each(@__normalizedNames_0) AS "n0"
)) AND "s"."LibraryId" IN (
    SELECT "l"."Id"
    FROM "Library" AS "l"
    WHERE EXISTS (
        SELECT 1
        FROM "AppUserLibrary" AS "a"
        INNER JOIN "AspNetUsers" AS "a0" ON "a"."AppUsersId" = "a0"."Id"
        WHERE "l"."Id" = "a"."LibrariesId" AND "a0"."Id" = @__userId_1)
)
ORDER BY "s"."Id"

This would probably take me some time to get my environment running and provide a PR, so if someone wants to take this information and implement a fix in the meantime that would probably be ideal!

Edit - OK I did get a Docker Image built and pushed to my k8s cluster and it seems like the Use Comic Vine Series matching slider is not respected. I added some log and despite having the slider switched on, the result is false. It seems like if this slider was working properly, perhaps the matching would work?

Edit 2 - I changed the normalizing function to always return CV format (as something seems to be explicitly passing in false to the function) and can import CBLs again... so, again, not sure what would be the permanent fix... but seems like if the Use Comic Vine Series matching slider was controlling the value of the useComicLibraryMatching variable, as I would expect it would, than this issue should be resolved. image