Merge pull request #2770 from bookwyrm-social/import-rating-parser

Catch value errors when parsing imported ratings
This commit is contained in:
Mouse Reeve 2023-04-25 16:21:25 -07:00 committed by GitHub
commit ac48457748
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class LibrarythingImporter(Importer):
normalized = {k: remove_brackets(entry.get(v)) for k, v in mappings.items()}
isbn_13 = normalized.get("isbn_13")
isbn_13 = isbn_13.split(", ") if isbn_13 else []
normalized["isbn_13"] = isbn_13[1] if len(isbn_13) > 0 else None
normalized["isbn_13"] = isbn_13[1] if len(isbn_13) > 1 else None
return normalized
def get_shelf(self, normalized_row):

View file

@ -252,9 +252,12 @@ class ImportItem(models.Model):
@property
def rating(self):
"""x/5 star rating for a book"""
if self.normalized_data.get("rating"):
if not self.normalized_data.get("rating"):
return None
try:
return float(self.normalized_data.get("rating"))
return None
except ValueError:
return None
@property
def date_added(self):