Repository: internetarchive/openlibrary

Issue:
Some ISBN searches error
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->

### Evidence / Screenshot (if possible)

Example:
**Errors:**
https://openlibrary.org/search?debug=true&isbn=1234567890

```
<class 'TypeError'> at /search
'NoneType' object is not iterable
```


**Expected example, gives no results:**
https://openlibrary.org/search?debug=true&isbn=12345

Looks like if an ISBN is sufficiently "ISBN like" (10 or 13 digits), but isn't a real ISBN, there is the possibility of an unhandled exceptions.


### Relevant url?
<!-- `https://openlibrary.org/...` -->

### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Go to ...
2. Do ...

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual:
* Expected:

### Details

- **Logged in (Y/N)?**
- **Browser type/version?**
- **Operating system?**
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->

Some ISBN searches error
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->

### Evidence / Screenshot (if possible)

Example:
**Errors:**
https://openlibrary.org/search?debug=true&isbn=1234567890

```
<class 'TypeError'> at /search
'NoneType' object is not iterable
```


**Expected example, gives no results:**
https://openlibrary.org/search?debug=true&isbn=12345

Looks like if an ISBN is sufficiently "ISBN like" (10 or 13 digits), but isn't a real ISBN, there is the possibility of an unhandled exceptions.


### Relevant url?
<!-- `https://openlibrary.org/...` -->

### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Go to ...
2. Do ...

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual:
* Expected:

### Details

- **Logged in (Y/N)?**
- **Browser type/version?**
- **Operating system?**
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->



Discussion:
The error is actually being raised by the dependency, [isbnlib](https://github.com/xlcnd/isbnlib). Looks like updating openlibrary/core/models.py to validate the ISBN, using e.g. isbnlib is_isbn10 before calling to_isbn_13 would pick up the issue with the invalid ISBN and prevent this.
The error is actually being raised by the dependency, [isbnlib](https://github.com/xlcnd/isbnlib). Looks like updating openlibrary/core/models.py to validate the ISBN, using e.g. isbnlib is_isbn10 before calling to_isbn_13 would pick up the issue with the invalid ISBN and prevent this.

Resolving patch:
diff --git a/openlibrary/core/models.py b/openlibrary/core/models.py
--- a/openlibrary/core/models.py
+++ b/openlibrary/core/models.py
@@ -409,6 +409,8 @@ def from_isbn(cls, isbn):
             return None  # consider raising ValueError
 
         isbn13 = to_isbn_13(isbn)
+        if isbn13 is None:
+            return None  # consider raising ValueError
         isbn10 = isbn_13_to_isbn_10(isbn13)
 
         # Attempt to fetch book from OL


Test patch: