Repository: internetarchive/openlibrary

Issue:
Deduplicate author aliases
The list of aliases for an author should be deduplicated before it is saved.

### Evidence / Screenshot (if possible)
I fixed the punctuation for the aliases list of the author below, which was a mix of commas and semi-colons, to make it all semi-colons, but when I saved the list, it left a bunch of duplicate entries in it. These should be removed before saving without the user having to go through and weed them out by hand.

### Relevant url?
https://openlibrary.org/authors/OL2399185A?_compare=Comparer&b=18&a=17&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: duplicates are left in list
* Expected: duplicates are removed



### Proposal & Constraints
The list should be deduplicated in an order preserving fashion, keeping the first occurrence of any alias and removing the later versions without changing the relative order of anything else.



### Stakeholders
<!-- @ tag stakeholders of this bug -->

Deduplicate author aliases
The list of aliases for an author should be deduplicated before it is saved.

### Evidence / Screenshot (if possible)
I fixed the punctuation for the aliases list of the author below, which was a mix of commas and semi-colons, to make it all semi-colons, but when I saved the list, it left a bunch of duplicate entries in it. These should be removed before saving without the user having to go through and weed them out by hand.

### Relevant url?
https://openlibrary.org/authors/OL2399185A?_compare=Comparer&b=18&a=17&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: duplicates are left in list
* Expected: duplicates are removed



### Proposal & Constraints
The list should be deduplicated in an order preserving fashion, keeping the first occurrence of any alias and removing the later versions without changing the relative order of anything else.



### Stakeholders
<!-- @ tag stakeholders of this bug -->



Discussion:

Resolving patch:
diff --git a/openlibrary/plugins/upstream/addbook.py b/openlibrary/plugins/upstream/addbook.py
--- a/openlibrary/plugins/upstream/addbook.py
+++ b/openlibrary/plugins/upstream/addbook.py
@@ -15,6 +15,7 @@
 from infogami.infobase.client import ClientException
 
 from openlibrary.plugins.worksearch.search import get_solr
+from openlibrary.core.helpers import uniq
 from openlibrary.i18n import gettext as _
 from openlibrary import accounts
 import logging
@@ -1009,9 +1010,12 @@ def process_input(self, i):
         if 'author' in i:
             author = trim_doc(i.author)
             alternate_names = author.get('alternate_names', None) or ''
-            author.alternate_names = [
-                name.strip() for name in alternate_names.split('\n') if name.strip()
-            ]
+            author.alternate_names = uniq(
+                [author.name]
+                + [
+                    name.strip() for name in alternate_names.split('\n') if name.strip()
+                ],
+            )[1:]
             author.links = author.get('links') or []
             return author
 


Test patch: