Language imports consistently on re-imports of books #10213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #10141 Internet Archive imports often missing language
Fix
Fixes language import issue by ensuring that language is correctly added to existing editions during import
Technical
Previously, the issue was that when importing an edition, the language field was not being correctly added to existing editions if it was missing, even if the import record contained a language.
To address this I added a helper function format_languages() to openlibrary/openlibrary/catalog/add_book/init.py,
to format the languages field, called by update_edition_with_rec_data() and build_query() in openlibrary/openlibrary/catalog/add_book/load_book.py, along with changes to both functions.
Testing
Tested this issue locally and reproduced the bug by running the following commands (generate command and import book).
$ curl -c cookies.txt -X POST "http://localhost:8080/account/login" -d "username=[email protected]&password=admin123"
$ curl -L -v -X POST "http://localhost:8080/api/import/ia"
-b ./cookies.txt
-d "identifier=isbn_9781849353946&require_marc=false&force_import=true"
The book should now appear under http://localhost:8080/books/OL5M/
However, if we delete the language field and reimport the book, the language fields remains missing.
http://localhost:8080/books/OL5M.yml?m=edit
After the changes, languages should now be correctly added.
Stakeholders
@scottbarnes