Repository: bookwyrm-social/bookwyrm

Issue:
When adding multiple authors to one book, only the first is added
**Describe the bug**

I would like to add multiple authors to a book (it's an anthology). When I add multiple authors to the book, via the "Add Another Author" button, only the first one is added.

**To Reproduce**

1. Edit book
2. Fill the info for one author (Charlie Jane Anders) in the input
3. Click "Add Another Author"
4. Fill the info for the new author in the second input
5. Click "Add Another Author"
6. Fill the info for that new author in that third input
7. Save book
8. The interface shows the message _Is "Charlie Jane Anders" one of these authors?_
9. Select one of the choices
10. Only Charlie Jane Anders has been added, the other authors don't show up.

**Expected behavior**

I would like to see all authors added, and the interface for selecting the right author (ie. _Is "Charlie Jane Anders" one of these authors?_) should show the choices for all the authors I add.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Instance**

boitam.eu (I expect this problem to be global)





Discussion:
I can confirm this was also happening to me when adding and also editing books, on wyrms.de a couple of weeks ago (not sure if the instance has had an update in the meantime)

Resolving patch:
diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py
--- a/bookwyrm/views/books/edit_book.py
+++ b/bookwyrm/views/books/edit_book.py
@@ -189,7 +189,7 @@ def add_authors(request, data):
                 "existing_isnis": exists,
             }
         )
-        return data
+    return data
 
 
 @require_POST


Test patch:
diff --git a/bookwyrm/tests/views/books/test_edit_book.py b/bookwyrm/tests/views/books/test_edit_book.py
--- a/bookwyrm/tests/views/books/test_edit_book.py
+++ b/bookwyrm/tests/views/books/test_edit_book.py
@@ -9,6 +9,7 @@
 from django.test.client import RequestFactory
 
 from bookwyrm import forms, models, views
+from bookwyrm.views.books.edit_book import add_authors
 from bookwyrm.tests.validate_html import validate_html
 from bookwyrm.tests.views.books.test_book import _setup_cover_url
 
@@ -214,3 +215,22 @@ def test_create_book_upload_cover_url(self):
 
         self.book.refresh_from_db()
         self.assertTrue(self.book.cover)
+
+    def test_add_authors_helper(self):
+        """converts form input into author matches"""
+        form = forms.EditionForm(instance=self.book)
+        form.data["title"] = "New Title"
+        form.data["last_edited_by"] = self.local_user.id
+        form.data["add_author"] = ["Sappho", "Some Guy"]
+        request = self.factory.post("", form.data)
+        request.user = self.local_user
+
+        with patch("bookwyrm.utils.isni.find_authors_by_name") as mock:
+            mock.return_value = []
+            result = add_authors(request, form.data)
+
+        self.assertTrue(result["confirm_mode"])
+        self.assertEqual(result["add_author"], ["Sappho", "Some Guy"])
+        self.assertEqual(len(result["author_matches"]), 2)
+        self.assertEqual(result["author_matches"][0]["name"], "Sappho")
+        self.assertEqual(result["author_matches"][1]["name"], "Some Guy")