Repository: internetarchive/openlibrary

Issue:
IA imports are ignoring *most* high quality MARC data
Even when there's a professionally cataloged MARC record associated with an Internet Archive import, none of the information in it is actually being imported. I've added some of the information available which you can see in the diff below (not guaranteed to be exhaustive).

This means that the incredibly poor quality metadata from Better World Books (BWB), ie. corrupted title, and Amazon (bad publisher) don't get corrected.

It also means that really useful finding information for users like the language and the classification of the edition aren't available.

Very strangely, it seems like my viewing the edition actually somehow triggered the Amazon import, which then overwrote the link to the IA MARC record with a link to the Amazon record in the footer of the edition page (fortunately I had the MARC page open in another tab, so I didn't lose it).

### Evidence / Screenshot (if possible)
![Screen Shot 2023-02-10 at 3 46 07 PM](https://user-images.githubusercontent.com/82178/218194378-37a73d59-cb0c-4bf3-b110-ef5bc925d52a.png)

### Relevant url?
https://openlibrary.org/show-records/ia:lesnoirsetlesrou0000garl
https://openlibrary.org/books/OL43522513M/Les_noirs_et_les_rouges?_compare=Comparer&b=6&a=3&m=diff

### 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: All useful information from the MARC record is imported to OpenLibrary and available for use in search.

### 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:

Resolving patch:
diff --git a/openlibrary/catalog/add_book/__init__.py b/openlibrary/catalog/add_book/__init__.py
--- a/openlibrary/catalog/add_book/__init__.py
+++ b/openlibrary/catalog/add_book/__init__.py
@@ -851,6 +851,7 @@ def update_edition_with_rec_data(
             need_edition_save = True
 
     other_edition_fields = [
+        'description',
         'number_of_pages',
         'publishers',
         'publish_date',


Test patch:
diff --git a/openlibrary/catalog/add_book/tests/test_add_book.py b/openlibrary/catalog/add_book/tests/test_add_book.py
--- a/openlibrary/catalog/add_book/tests/test_add_book.py
+++ b/openlibrary/catalog/add_book/tests/test_add_book.py
@@ -1265,3 +1265,53 @@ def test_validate_record(name, rec, error) -> None:
             validate_record(rec)
     else:
         assert validate_record(rec) is None, f"Test failed: {name}"  # type: ignore [func-returns-value]
+
+
+def test_reimport_updates_edition_and_work_description(mock_site) -> None:
+    author = {
+        'type': {'key': '/type/author'},
+        'name': 'John Smith',
+        'key': '/authors/OL1A',
+    }
+
+    existing_work = {
+        'authors': [{'author': '/authors/OL1A', 'type': {'key': '/type/author_role'}}],
+        'key': '/works/OL1W',
+        'title': 'A Good Book',
+        'type': {'key': '/type/work'},
+    }
+
+    existing_edition = {
+        'key': '/books/OL1M',
+        'title': 'A Good Book',
+        'publishers': ['Black Spot'],
+        'type': {'key': '/type/edition'},
+        'source_records': ['ia:someocaid'],
+        'publish_date': 'Jan 09, 2011',
+        'isbn_10': ['1234567890'],
+        'works': [{'key': '/works/OL1W'}],
+    }
+
+    mock_site.save(author)
+    mock_site.save(existing_work)
+    mock_site.save(existing_edition)
+
+    rec = {
+        'source_records': 'ia:someocaid',
+        'title': 'A Good Book',
+        'authors': [{'name': 'John Smith'}],
+        'publishers': ['Black Spot'],
+        'publish_date': 'Jan 09, 2011',
+        'isbn_10': ['1234567890'],
+        'description': 'A genuinely enjoyable read.',
+    }
+
+    reply = load(rec)
+    assert reply['success'] is True
+    assert reply['edition']['status'] == 'modified'
+    assert reply['work']['status'] == 'modified'
+    assert reply['work']['key'] == '/works/OL1W'
+    edition = mock_site.get(reply['edition']['key'])
+    work = mock_site.get(reply['work']['key'])
+    assert edition.description == "A genuinely enjoyable read."
+    assert work.description == "A genuinely enjoyable read."