-
Notifications
You must be signed in to change notification settings - Fork 54
Handle Science Museum errors with batches larger than 50 pages #905
Conversation
In doing some poking around on the Science Museum side of things, I was able to find this issue: TheScienceMuseum/collectionsonline#735. Looks like they came to a similar conclusion as us: WordPress/openverse-api#857 Pagination is a hard problem it seems! What's interesting is that their API limits to the first 150 pages still: Do you think we should reach out for this case and file a bug on their repo, given that the issue we're seeing is on page 50 and not 150? And also given that a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent! I'm not able to test it right now, but the code looks good. love the new tests 🙌🏼 Just a few notes on wording and my previous comments wondering if we should file an upstream issue.
openverse_catalog/dags/providers/provider_api_scripts/science_museum.py
Outdated
Show resolved
Hide resolved
openverse_catalog/dags/providers/provider_api_scripts/science_museum.py
Outdated
Show resolved
Hide resolved
@pytest.mark.parametrize( | ||
"next_url, page_number, should_continue, should_alert", | ||
[ | ||
# Happy path, should continue | ||
( | ||
"https://collection.sciencemuseumgroup.org.uk/search/date[from]/1875/date[to]/1900/images/image_license?page[size]=100&page[number]=20", | ||
20, | ||
True, | ||
False, | ||
), | ||
# Don't continue when next_url is None, regardless of page number | ||
(None, 20, False, False), | ||
(None, 50, False, False), | ||
# Don't continue and DO alert when page number is 50 and there is a next_url | ||
( | ||
"https://collection.sciencemuseumgroup.org.uk/search/date[from]/1875/date[to]/1900/images/image_license?page[size]=100&page[number]=50", | ||
50, | ||
False, | ||
True, | ||
), | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic! 🤩
I was able to test, this worked well! One note, your example has: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Lots of nice improvements here.
Fixes
Fixes WordPress/openverse#1363
Background
The Science Museum API appears to be throwing 400 errors when you attempt to access a page number greater than 50 for large datasets, even when there should legitimately be > 50 pages. For example, a recent run received this response for the 50th page of a dataset:
Note that
total_pages
> 50, and thelinks
section does contain a link to page 51. However if you attempt to actually request page 51, you get a 400 error and the DAG eventually errors after a few retry attempts.We were already splitting the data from the Science Museum up into
year_range
intervals to try to get smaller batches of data, presumably to avoid this error. It looks as though some of the year ranges are now too large.Description
This PR:
year_range
intervals so that none contains more than 50 pages of dataIn order to get the Slack alert working I had to make a small modification to pass
dag_id
into provider data ingesters, so there are a few changes related to that. I also updated docs and cleaned up a few small things.Testing Instructions
just test
Run the DAG locally and ensure that you don't see any Slack alerts or errors. Setting an
ingestion_limit
will prevent the buggy scenario from being reached, so if you want to speed up the process you can instead manually edit the startingpage_number
inget_next_query_params
:To test the Slack alerting when a page number greater than 50 is reached, you can edit the
year_ranges
locally to be a few very long ranges that will definitely have more than 50 pages:Then run the DAG again and verify that you can see the
send_alert
message in the logs, but ingestion continues. (Ie you should ingest the first 50 pages worth of data for each of your long ranges).Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin