valos/Komikku
9
102
Fork
You've already forked Komikku
29

[Models] Gracefully handle UNIQUE constraints. #902

Closed
lilyp wants to merge 1 commit from lilyp/fix-UNIQUE-crash into main AGit
pull from: lilyp/fix-UNIQUE-crash
merge into: valos:main
valos:main
valos:gnome-49
valos:gnome-48
valos:gnome-47
valos:gnome-46
valos:website
valos:gtk3
Contributor
Copy link

In Manga.new(), id_ may end up as None if the UNIQUE constraint on
(server_id, slug) is violated. Consequently, manga ends up being None,
and an AttributeError is raised by accessing manga.path.

This is typically the result of using the Explorer to browse a manga already
in the library, leading to an application crash.

Error: An unhandled exception occurs
Traceback (most recent call last):
 File "/path/to/python/site-packages/komikku/explorer/search/__init__.py", line 462, in complete_get
 manga = Manga.new(manga_data, self.server, Settings.get_default().long_strip_detection)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/path/to/python/site-packages/komikku/models/database/mangas.py", line 116, in new
 if not os.path.exists(manga.path):
AttributeError: 'NoneType' object has no attribute 'path'
In Manga.new(), id_ may end up as None if the UNIQUE constraint on (server_id, slug) is violated. Consequently, manga ends up being None, and an AttributeError is raised by accessing manga.path. This is typically the result of using the Explorer to browse a manga already in the library, leading to an application crash. ``` Error: An unhandled exception occurs Traceback (most recent call last): File "/path/to/python/site-packages/komikku/explorer/search/__init__.py", line 462, in complete_get manga = Manga.new(manga_data, self.server, Settings.get_default().long_strip_detection) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/python/site-packages/komikku/models/database/mangas.py", line 116, in new if not os.path.exists(manga.path): AttributeError: 'NoneType' object has no attribute 'path' ```
In Manga.new(), id_ may end up as None if the UNIQUE constraint on
(server_id, slug) is violated. Consequently, manga ends up being None,
and an AttributeError is raised by accessing manga.path.
This is typically the result of using the Explorer to browse a manga already
in the library, leading to an application crash.
```
Error: An unhandled exception occurs
Traceback (most recent call last):
 File "/path/to/python/site-packages/komikku/explorer/search/__init__.py", line 462, in complete_get
 manga = Manga.new(manga_data, self.server, Settings.get_default().long_strip_detection)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/path/to/python/site-packages/komikku/models/database/mangas.py", line 116, in new
 if not os.path.exists(manga.path):
AttributeError: 'NoneType' object has no attribute 'path'
```
Owner
Copy link

Damn, this shouldn't be happening. How did you do that? Is it reproducible? I'd like to understand.

Damn, this shouldn't be happening. How did you do that? Is it reproducible? I'd like to understand.
Author
Contributor
Copy link

It appears to depend on the server. With dynasty, if I happen to add the same manga twice (any one), the above occurs; with xkcd it curiously doesn't, with Pepper&Carrot and Mangadex it also doesn't. Chances are, something is wrong with the dynasty server, but IMHO applying defense in depth sounds reasonable to me.

It appears to depend on the server. With dynasty, if I happen to add the same manga twice (any one), the above occurs; with xkcd it curiously doesn't, with Pepper&Carrot and Mangadex it also doesn't. Chances are, something is wrong with the dynasty server, but IMHO applying defense in depth sounds reasonable to me.
Owner
Copy link

@lilyp wrote in #902 (comment):

IMHO applying defense in depth sounds reasonable to me.

The problem is that there's already protection in place, so this shouldn't happen at all.
Manga.new() can't be call with a (server_id, slug) that already exists.

See komikku/explorer/search/init.py

@lilyp wrote in https://codeberg.org/valos/Komikku/pulls/902#issuecomment-18366062: > IMHO applying defense in depth sounds reasonable to me. The problem is that there's already protection in place, so this shouldn't happen at all. Manga.new() can't be call with a (server_id, slug) that already exists. See [komikku/explorer/search/__init__.py](https://codeberg.org/valos/Komikku/src/branch/main/komikku/explorer/search/__init__.py#L506)
Owner
Copy link

The problem was caused by the Dynasty server, which modified the slug returned by the search (for chapters only) in get_manga_data method.

See 383b4f7907

The problem was caused by the Dynasty server, which modified the slug returned by the search (for chapters only) in `get_manga_data` method. See 383b4f7907
valos closed this pull request 2026年07月05日 02:34:14 +02:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
valos/Komikku!902
Reference in a new issue
valos/Komikku
No description provided.
Delete branch "lilyp/fix-UNIQUE-crash"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?