ALTIMPORT: handle case where results not set
In the condition where altimport can find the author but can't find the book in the library, results is not set. Changing to a try/except was the easiest way to fix this. Alternative is to make results and empty set but I couldn't decide where that would be appropriate, so I just wrapped in a exception handler.
diff --git a/lazylibrarian/postprocess.py b/lazylibrarian/postprocess.py
index 0a39666e..5c61437d 100644
--- a/lazylibrarian/postprocess.py
+++ b/lazylibrarian/postprocess.py
@@ -552,17 +552,19 @@ def process_alternate(source_dir=None, library='eBook', automerge=False):
if not bookid:
msg = "%s %s by %s not found in database" % (library, bookname, authorname)
- if not results:
+ try:
+ if results:
+ msg += ', No match found'
+ logger.warning(msg)
+ msg = "Closest match (%s%% %s%%) %s: %s" % (results[0]['author_fuzz'], results[0]['book_fuzz'],
+ results[0]['authorname'], results[0]['bookname'])
+ if results[0]['authorid'] != authorid:
+ msg += ' wrong authorid'
+ logger.warning(msg)
+ except UnboundLocalError:
msg += ', No results returned'
logger.warning(msg)
- else:
- msg += ', No match found'
- logger.warning(msg)
- msg = "Closest match (%s%% %s%%) %s: %s" % (results[0]['author_fuzz'], results[0]['book_fuzz'],
- results[0]['authorname'], results[0]['bookname'])
- if results[0]['authorid'] != authorid:
- msg += ' wrong authorid'
- logger.warning(msg)
+
return False
db = database.DBConnection()