Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Preemptively fail unparsable/unusable Europeana URLs (#3845)

Madison Swain-Bowden193468872f38
diff --git a/catalog/dags/providers/provider_api_scripts/europeana.py b/catalog/dags/providers/provider_api_scripts/europeana.py
index 63f44685d..e96c2d272 100644
--- a/catalog/dags/providers/provider_api_scripts/europeana.py
+++ b/catalog/dags/providers/provider_api_scripts/europeana.py
@@ -98,7 +98,15 @@ class EuropeanaRecordBuilder:
@raise_if_empty
def _get_image_url(self, data: dict) -> str | None:
group = data.get("edmIsShownBy")
- return group[0] if group else None
+ if not group:
+ return None
+ url = group[0]
+ # Some Europeana URLs may have prefixes, or reference Dropbox (which we can't
+ # include in our catalog because we cannot access them directly ourselves).
+ # E.g.: L-APC248-https://www.dropbox.com/s/i1pqizm1joof8y1/Belgium_Diptyque%20_MAR-SGP-CO1.jpg?raw=1
+ if "dropbox.com" in url:
+ return None
+ return url
@raise_if_empty
def _get_foreign_identifier(self, data: dict) -> str | None:
diff --git a/catalog/tests/dags/providers/provider_api_scripts/test_europeana.py b/catalog/tests/dags/providers/provider_api_scripts/test_europeana.py
index 31e0d422a..a87aab5d7 100644
--- a/catalog/tests/dags/providers/provider_api_scripts/test_europeana.py
+++ b/catalog/tests/dags/providers/provider_api_scripts/test_europeana.py
@@ -9,6 +9,7 @@ from common.licenses import LicenseInfo, get_license_info
from common.loader import provider_details as prov
from common.storage.image import ImageStore
from providers.provider_api_scripts.europeana import (
+ EmptyRequiredFieldException,
EuropeanaDataIngester,
EuropeanaRecordBuilder,
)
@@ -254,6 +255,19 @@ def test_get_foreign_landing_url_without_edmIsShownAt(record_builder):
)
+ "data",
+ [
+ {},
+ {"edmIsShownBy": None},
+ {"edmIsShownBy": ["dropbox.com/value"]},
+ ],
+)
+def test_get_image_url_empty(data, record_builder):
+ with pytest.raises(EmptyRequiredFieldException):
+ assert record_builder._get_image_url(data)
+
+
@pytest.mark.parametrize(
"item_data, expected",
[