Skip to content

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

Properly handle "None" values returned from Freesound API (#327)

Madison Swain-Bowden5a954f919fec
diff --git a/openverse_catalog/dags/providers/provider_api_scripts/freesound.py b/openverse_catalog/dags/providers/provider_api_scripts/freesound.py
index 44a2ccd57..08e130ada 100644
--- a/openverse_catalog/dags/providers/provider_api_scripts/freesound.py
+++ b/openverse_catalog/dags/providers/provider_api_scripts/freesound.py
@@ -136,6 +136,9 @@ def _get_batch_json(endpoint=ENDPOINT, headers=None, retries=RETRIES, query_para
def _process_item_batch(items_batch):
for item in items_batch:
+ # Freesound sometimes returns results that are just "None"
+ if item is None:
+ continue
item_meta_data = _extract_audio_data(item)
if item_meta_data is None:
continue
diff --git a/tests/dags/providers/provider_api_scripts/test_freesound.py b/tests/dags/providers/provider_api_scripts/test_freesound.py
index 45887e9a9..5073d1fe4 100644
--- a/tests/dags/providers/provider_api_scripts/test_freesound.py
+++ b/tests/dags/providers/provider_api_scripts/test_freesound.py
@@ -67,8 +67,11 @@ def test_get_items():
assert expected_audio_count == actual_audio_count
-def test_process_item_batch_handles_example_batch(audio_data):
[email protected]("has_nones", [False, True])
+def test_process_item_batch_handles_example_batch(has_nones, audio_data):
items_batch = [audio_data]
+ if has_nones:
+ items_batch = [None, None, audio_data, None]
with patch.object(freesound.audio_store, "add_item", return_value=1) as mock_add:
freesound._process_item_batch(items_batch)
mock_add.assert_called_once()