|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Enthusiast
![]() Posts: 27
Karma: 30
Join Date: Jul 2011
Device: none
|
cache.set_field() Why "Bad binding argument type supplied - argument #1?
I am writing a plugin to assist users in fixing libraries where many books have the fields values scrambled.
I have a method that works when run as a test directly from my plugin gui: Code:
class SomeGUI:
...
def button_pressed_demo(self):
field_name = 'authors'
value = "Neil Gaiman"
db_cache_api = self.gui_db.new_api
rows = self.gui.library_view.selectionModel().selectedRows()
ids = list(map(self.gui.library_view.model().id, rows))
first_selected = ids[0]
BookDemangler.write_publication_field(db_cache_api, first_selected, field_name, value) # This works
class BookDemangler:
...
@staticmethod
def write_publication_field(db_cache_api, book_id, field_name, value):
if field_name == 'author_sort':
field_name = 'authors'
value = Workshop.flip_author_sorts(value)
print("Book \"%s\"->Setting field \"%s\" to value \"%s\"" % (str(book_id), field_name, value))
bitvm = {book_id: value}
changed = db_cache_api.set_field(name=field_name,
book_id_to_val_map=bitvm,
allow_case_change=True)
Code:
class SomeGUI:
...
def process_authorship(self):
from calibre.ebooks.metadata.meta import set_metadata
from calibre.gui2 import error_dialog, info_dialog
# Get currently selected books
rows = self.gui.library_view.selectionModel().selectedRows()
if not rows or len(rows) == 0:
return error_dialog(self.gui, 'Cannot demangle books', 'No books selected', show=True)
# Map the rows to book ids
ids = list(map(self.gui.library_view.model().id, rows))
db_cache_api = self.gui_db.new_api
if db_cache_api:
for book_id in ids:
BookDemangler.demangle(db_cache_api, book_id) # Fails
else:
raise RuntimeError("Failed to obtain database_api cache object.")
info_dialog(self, 'Accessed books', 'Ran processor on %d book(s)' % len(ids), show=True)
BookDemangler.demangle() attempts to guess the correct author, title, and series values from mangled metadata. When I review the arguments I pass to set_field(), I am pretty confident in field name and values being correct. That leads me to suspect
Thanks for any help! |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,626
Karma: 28549046
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
According to that error you are passing in a Metadata object rather than an actual value.
|
|
|
|
|
|
#3 |
|
Enthusiast
![]() Posts: 27
Karma: 30
Join Date: Jul 2011
Device: none
|
Thanks Kovid!
It was the book_id. An method expecting an older version of write_publication_field() was passing the book's metadata object instead of the int book_id. |
|
|
|
![]() |
| Tags |
| database, plug-ins |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| --extra-css argument ignored | paipa | Conversion | 10 | 09-05-2014 11:50 AM |
| The operator >> is undefined for the argument type(s) float, float | twobob | Kindle Developer's Corner | 10 | 09-05-2012 01:50 PM |
| for the sake of argument... | Opus | Amazon Kindle | 9 | 06-21-2010 11:55 PM |
| 8 Ways To Handle An Argument | moon light | Lounge | 11 | 08-26-2009 10:16 PM |
| An argument we are having at work... | ficbot | News | 125 | 08-05-2009 09:09 AM |