diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index d8ea501c9b..83a8797e21 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -209,7 +209,7 @@ class StyledItemDelegate(QStyledItemDelegate): def createEditor(self, parent, option, index): e = self.create_editor(parent, option, index) - if (book_id := index.data(Qt.ItemDataRole.UserRole)) and isinstance(book_id, int): + if e is not None and (book_id := index.data(Qt.ItemDataRole.UserRole)) and isinstance(book_id, int): setattr(e, 'underlying_book_id', book_id) return e