From a788f3699c2fb8d9fad06d99e631a771c81e600e Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 3 Mar 2024 18:27:40 +0300 Subject: [PATCH] Fix(DB): Fix bug with adding same genre to book --- docs-ru/news.rst | 5 +++++ docs/news.rst | 5 +++++ m_librarian/inp.py | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs-ru/news.rst b/docs-ru/news.rst index a66ea93..fbdd698 100644 --- a/docs-ru/news.rst +++ b/docs-ru/news.rst @@ -1,6 +1,11 @@ Новости ======= +Версия 0.3.2 (2024-03-??) +------------------------- + +* Исправлена ошибка с повторным добавлением жанра книги. + Версия 0.3.1 (2024-02-25) ------------------------- diff --git a/docs/news.rst b/docs/news.rst index 4d1fe11..ce0b046 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -1,6 +1,11 @@ News ==== +Version 0.3.2 (2024-03-??) +-------------------------- + +* Fix a bug with adding the same genre to a book. + Version 0.3.1 (2024-02-25) -------------------------- diff --git a/m_librarian/inp.py b/m_librarian/inp.py index f910b10..6d3bd7d 100644 --- a/m_librarian/inp.py +++ b/m_librarian/inp.py @@ -2,7 +2,7 @@ import os from zipfile import ZipFile -from sqlobject import sqlhub +from sqlobject import dberrors, sqlhub from sqlobject.sqlbuilder import Select from .db import Author, Book, Extension, Genre, Language, \ @@ -71,7 +71,10 @@ def import_inp_line(archive, parts): for genre in genres.split(':'): if genre: genre_row = insert_name(Genre, genre, title=genre) - book.addGenre(genre_row) + try: + book.addGenre(genre_row) + except dberrors.DuplicateEntryError: + pass # The genre has already been added def tounicode(s): -- 2.39.2