Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Check required fields in media store #1086

Merged
merged 5 commits into from
Apr 4, 2023

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Apr 3, 2023

Fixes

Fixes WordPress/openverse#1281 by @stacimc

Description

This PR:

  • raises a ValueError in the MediaStore's clean_media_metadata if any of the required fields foreign_landing_url, url, and foreign_identifier are missing.
  • Adds some new error handling for Metropolitan:
    • Returns early if no image urls (primary or additional) can be pulled
    • Handles missing isPublicDomain key (in addition to explicit False)
    • Returns early if missing foreign landing url

Testing Instructions

View the new tests.

The Metropolitan issue is hard to reproduce organically. You can manually update the metropolitan DAG code to add a None image here:

        image_list = [main_image] + other_images + [None]

Then run the DAG and ensure that you do not see any errors (because no records with None url are passed to the MediaStore).

You can test that the error handling in the media store is working by hard-coding None for one of the required fields in the results here. Then you should see the task fail when you run the DAG, with an error message like:

Record missing required field: `foreign_landing_url`

Checklist

  • My pull request has a descriptive title (not a vague title like
    Update index.md).
  • My pull request targets the default branch of the repository (main) or
    a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible
    errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@stacimc stacimc added bug Something isn't working 🟧 priority: high Stalls work on the project or its dependents 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository 🧱 stack: catalog Related to the catalog and Airflow DAGs labels Apr 3, 2023
@stacimc stacimc requested a review from a team as a code owner April 3, 2023 20:47
@stacimc stacimc self-assigned this Apr 3, 2023
Comment on lines 123 to 130
for field in [
"foreign_identifier",
"foreign_landing_url",
f"{self.media_type}_url",
]:
if media_data.get(field) is None:
logger.debug(f"Discarding media due to missing {field}")
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't believe this wasn't checked before 😱 Well noticed. However, I wonder whether just ignoring items when missing fields at this point, in the media store class, is the right approach. I am slightly inclined to raise an exception here and have each provider DAG handle theses cases explicitly. Sometimes, if a field is not found another from the source can be used in replacement, e.g. this is common in the creator_url. These errors have also helped me realize some gaps in the logic in a few cases!

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes, if a field is not found another from the source can be used in replacement, e.g. this is common in the creator_url

That's a really great point -- raising an exception here might help us spot these opportunities in some cases, and even in cases where the record should ultimately be discarded, it'll be an easy fix in the provider class. I'll update!

Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following my previous comment, shouldn't we also add the field validations in the Metropolitan DAG? It could skip processing for more than one image, cutting times a bit.

Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like what y'all have proposed & discussed! Given how rapidly we are able to iterate on ingestion DAGs, I like the idea of failing sooner and addressing issues on a per-provider basis. That, in its own way, can serve as a data health check - if the data changes and our assumptions no longer hold, we want to know about it.

I have one logging suggestion which is blocking, but otherwise this looks great!

@@ -63,6 +63,13 @@
],
)

TEST_REQUIRED_FIELDS = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 😄

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@stacimc stacimc merged commit 8a8bef4 into main Apr 4, 2023
@stacimc stacimc deleted the update/check-required-fields-in-media-store branch April 4, 2023 19:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository bug Something isn't working 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: catalog Related to the catalog and Airflow DAGs
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Metropolitan receives records with None url
4 participants