Repository: internetarchive/openlibrary

Issue:
Remove invalidate dates from editions during create/edit (e.g. 9999)
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->

### Evidence / Screenshot (if possible)

Proposing somewhere in catalog that we prevent any record from having future dates (may be most applicable to BWB / promise items)
https://github.com/internetarchive/openlibrary/blob/master/openlibrary/catalog/add_book/__init__.py#L740

### 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:

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
@@ -785,6 +785,10 @@ def normalize_import_record(rec: dict) -> None:
     if not isinstance(rec['source_records'], list):
         rec['source_records'] = [rec['source_records']]
 
+    publication_year = get_publication_year(rec.get('publish_date'))
+    if publication_year and published_in_future_year(publication_year):
+        del rec['publish_date']
+
     # Split subtitle if required and not already present
     if ':' in rec.get('title', '') and not rec.get('subtitle'):
         title, subtitle = split_subtitle(rec.get('title'))


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
@@ -2,6 +2,7 @@
 import pytest
 
 from copy import deepcopy
+from datetime import datetime
 from infogami.infobase.client import Nothing
 
 from infogami.infobase.core import Text
@@ -18,6 +19,7 @@
     isbns_from_record,
     load,
     load_data,
+    normalize_import_record,
     should_overwrite_promise_item,
     split_subtitle,
     RequiredField,
@@ -1451,3 +1453,25 @@ def test_passing_edition_to_load_data_overwrites_edition_with_rec_data(
             'ia:newlyscannedpromiseitem',
         ]
         assert edition.works[0]['key'] == '/works/OL1W'
+
+
+class TestNormalizeImportRecord:
+    @pytest.mark.parametrize(
+        'year, expected',
+        [
+            ("2000-11-11", True),
+            (str(datetime.now().year), True),
+            (str(datetime.now().year + 1), False),
+            ("9999-01-01", False),
+        ],
+    )
+    def test_future_publication_dates_are_deleted(self, year, expected):
+        """It should be impossible to import books publish_date in a future year."""
+        rec = {
+            'title': 'test book',
+            'source_records': ['ia:blob'],
+            'publish_date': year,
+        }
+        normalize_import_record(rec=rec)
+        result = 'publish_date' in rec
+        assert result == expected