Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Make foreign_identifier required in `add_item` (#1887)
Olga Bulat52fae1d7d511
diff --git a/catalog/dags/common/storage/audio.py b/catalog/dags/common/storage/audio.pyindex b4bcb71ca..7384015f4 100644--- a/catalog/dags/common/storage/audio.py+++ b/catalog/dags/common/storage/audio.py@@ -46,10 +46,10 @@ class AudioStore(MediaStore):foreign_landing_url: str,audio_url: str,license_info: LicenseInfo,+ foreign_identifier: str,thumbnail_url: str | None = None,filesize: int | None = None,filetype: str | None = None,- foreign_identifier: str | None = None,creator: str | None = None,creator_url: str | None = None,title: str | None = None,@@ -72,7 +72,8 @@ class AudioStore(MediaStore):**kwargs,):"""- Add information for a single audio to the AudioStore.+ Add information for a single audio to the AudioStore. Audio data+ without the required parameters will be discarded.Required Arguments:@@ -93,7 +94,8 @@ class AudioStore(MediaStore):In the case of the `publicdomain` license, which has no version,one should pass `common.license.constants.NO_VERSION` here.- Audio data without the required parameters will be discarded.+ foreign_identifier: Unique identifier for the audio on the+ source site.Optional Arguments:@@ -101,8 +103,6 @@ class AudioStore(MediaStore):the audio.filesize: Size of the main file in bytesfiletype: The filetype of the main file, eg. 'mp3', 'ogg'.- foreign_identifier: Unique identifier for the audio on the- source site.creator: The creator of the audio.creator_url: The user page, or home page of the creator.title: Title of the audio.diff --git a/catalog/dags/common/storage/image.py b/catalog/dags/common/storage/image.pyindex 01ad1f14a..ab3307ba8 100644--- a/catalog/dags/common/storage/image.py+++ b/catalog/dags/common/storage/image.py@@ -46,10 +46,10 @@ class ImageStore(MediaStore):foreign_landing_url: str,image_url: str,license_info: LicenseInfo,+ foreign_identifier: str,thumbnail_url: str | None = None,filesize: int | None = None,filetype: str | None = None,- foreign_identifier: str | None = None,width: int | None = None,height: int | None = None,creator: str | None = None,@@ -64,7 +64,8 @@ class ImageStore(MediaStore):**kwargs,):"""- Add information for a single image to the ImageStore.+ Add information for a single image to the ImageStore. Image data+ without the required parameters will be discarded.Required Arguments:foreign_landing_url: URL of page where the image lives on the@@ -85,7 +86,9 @@ class ImageStore(MediaStore):In the case of the `publicdomain` license, which has no version,one should pass `common.license.constants.NO_VERSION` here.- Image data without the required parameters will be discarded.+ foreign_identifier: Unique identifier for the image on the+ source site.+Optional Arguments:@@ -93,8 +96,6 @@ class ImageStore(MediaStore):the image.filesize: Size of the image file in bytes.filetype: eg. 'jpg', 'svg'.- foreign_identifier: Unique identifier for the image on the- source site.width: in pixels.height: in pixels.creator: The creator of the image.diff --git a/catalog/dags/common/storage/media.py b/catalog/dags/common/storage/media.pyindex 791d4adea..dce51fb76 100644--- a/catalog/dags/common/storage/media.py+++ b/catalog/dags/common/storage/media.py@@ -111,14 +111,16 @@ class MediaStore(metaclass=abc.ABCMeta):- add `provider`,- add default `category`, if available.- Returns None if license is invalid. Raises an error if missing required- `foreign_identifier`, `foreign_landing_url`, or `url`.+ Raises an error if missing any of the required fields:+ `license_info`, `foreign_identifier`, `foreign_landing_url`, or `url`.+ TODO: simplify when the license_info is refactored to only hold valid licenses."""- if media_data["license_info"].license is None or not is_valid_license_info(- media_data["license_info"]+ if (+ not media_data["license_info"]+ or media_data["license_info"].license is None+ or not is_valid_license_info(media_data["license_info"])):- logger.debug("Discarding media due to invalid license")- return None+ raise ValueError("Record missing required field: `license_info`")for field in ["foreign_identifier",diff --git a/catalog/tests/dags/common/storage/test_media.py b/catalog/tests/dags/common/storage/test_media.pyindex 2f0419dd1..7e754ac3c 100644--- a/catalog/tests/dags/common/storage/test_media.py+++ b/catalog/tests/dags/common/storage/test_media.py@@ -263,7 +263,7 @@ def test_MediaStore_clean_media_metadata_does_not_replace_category_with_default(@pytest.mark.parametrize(- "field", ("foreign_identifier", "foreign_landing_url", "image_url")+ "field", ("foreign_identifier", "foreign_landing_url", "image_url", "license_info"))def test_MediaStore_clean_media_metadata_raises_when_missing_required_field(field,