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

Handle case where Wikimedia has no audio metadata #443

Merged
merged 1 commit into from Mar 30, 2022

Conversation

AetherUnbound
Copy link
Contributor

Fixes

Fixes WordPress/openverse#1611 by @stacimc

Description

This PR increases the scope of error handling within the Wikimedia Commons provider script to handle cases where there is no audio metadata.

While I couldn't get the exact case that happened in production, I was able to reproduce the error by removing the "audio" section of one of our test files:

$ pytest -n 1 -k test_wikimedia
Test session starts (platform: linux, Python 3.9.7, pytest 6.2.5, pytest-sugar 0.9.4)
rootdir: /usr/local/airflow, configfile: pytest.ini
plugins: raises-0.11, xdist-2.5.0, mock-3.6.1, anyio-3.5.0, forked-1.4.0, flaky-3.7.0, sugar-0.9.4
gw0 [35]lecting ... 

 tests/dags/providers/provider_api_scripts/test_wikimedia_commons.py ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓                                                                                                                                                                      97% █████████▊

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_parse_audio_file_data_parses_wav_audio_data_missing_streams ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
[gw0] linux -- Python 3.9.7 /usr/local/bin/python

    def test_parse_audio_file_data_parses_wav_audio_data_missing_streams():
        with open(RESOURCES / "audio_filedata_wav.json") as f:
            file_metadata = json.load(f)
        # Remove any actual audio data
        file_metadata = file_metadata[:5] + file_metadata[6:]
        original_data = {"meta_data": {}}
>       actual_parsed_data = wmc._parse_audio_file_data(original_data, file_metadata)

tests/dags/providers/provider_api_scripts/test_wikimedia_commons.py:437: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py:288: in _parse_audio_file_data
    streams = _get_value_by_name(audio, "streams")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

key_value_list = None, prop_name = 'streams'

    def _get_value_by_name(key_value_list: list, prop_name: str):
>       prop_list = [
            key_value_pair
            for key_value_pair in key_value_list
            if key_value_pair["name"] == prop_name
        ]
E       TypeError: 'NoneType' object is not iterable

openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py:267: TypeError

 tests/dags/providers/provider_api_scripts/test_wikimedia_commons.py ⨯                                                                                                                                                                                                      100% ██████████
================================================================================================================================= short test summary info =================================================================================================================================
FAILED tests/dags/providers/provider_api_scripts/test_wikimedia_commons.py::test_parse_audio_file_data_parses_wav_audio_data_missing_streams - TypeError: 'NoneType' object is not iterable

Results (4.25s):
      34 passed
       1 failed
         - tests/dags/providers/provider_api_scripts/test_wikimedia_commons.py:431 test_parse_audio_file_data_parses_wav_audio_data_missing_streams

From there I moved around the try/except block, and corrected the expected test results to align with what we'd see in these cases.

Testing Instructions

  1. just test
  2. If you're feeling spicy, run the Wikimedia Commons script with --date 2022-03-22

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.

@AetherUnbound AetherUnbound requested a review from a team as a code owner March 25, 2022 21:53
@dhruvkb dhruvkb added this to Needs review in Openverse PRs Mar 25, 2022
@dhruvkb dhruvkb added 💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents labels Mar 25, 2022
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.

I am not, in fact, feeling spicy, as discussed in the testing notes, but this looks very straightforward and the tests pass locally.

Openverse PRs automation moved this from Needs review to Reviewer approved Mar 29, 2022
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

The change looks simple, and all the tests pass!

Copy link
Contributor

@stacimc stacimc 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!

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.

LGTM! 🚀

@openverse-bot
Copy link
Contributor

✅ LGTM!

@AetherUnbound AetherUnbound merged commit 1d9c96d into main Mar 30, 2022
Openverse PRs automation moved this from Reviewer approved to Merged! Mar 30, 2022
@AetherUnbound AetherUnbound deleted the bugfix/wc-audio branch March 30, 2022 19:14
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 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents
Projects
No open projects
Openverse PRs
  
Merged!
Development

Successfully merging this pull request may close these issues.

Wikimedia Commons errors when audio is None
7 participants