Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix target_window when redirect is > 1 day #53

Merged
merged 4 commits into from Oct 19, 2020

Conversation

Mr0grog
Copy link
Member

@Mr0grog Mr0grog commented Oct 19, 2020

The target_window parameter for get_memento() is supposed to limit how far off in time from the requested time you can get a memento for when the exact parameter is False. However, it only works correctly when the target is off by less than a day! (The scenarios we were originally concerned with in EDGI almost invariably were on the scale of a few hours, so I guess that's how this error snuck in. 😬) If you set exact=True (the default), this bug wouldn’t be triggered.

We were checking the target offset by the number of seconds, irrespective of the additional number of days involved. We should have been checking by total_seconds, which converts the days into seconds and includes them. I’ve also added tests here to make sure this problem doesn’t occur again.

This PR targets the v0.2.x branch; I’ll add a new PR for main (which is now for v0.3.x) after this merges.

The `target_window` parameter for `get_memento()` is supposed to limit how far off in time from the requested time you can get a memento for when the `exact` parameter is `False`. However, it only works correctly when the target is off by less than a day! (The scenarios we were originally concerned with in EDGI almost invariably were on the scale of a few hours, so I guess that's how this error snuck in.) We were checking the target offset by the number of seconds, irrespective of the additional number of days involved. We should have been checking by `total_seconds`, which converts the days into seconds and includes them.
@Mr0grog Mr0grog added the bug Something isn't working label Oct 19, 2020
@Mr0grog
Copy link
Member Author

Mr0grog commented Oct 19, 2020

Example case — If you set a target_window of 5 minutes:

url = 'https://web.archive.org/web/20200101000000id_/https://epa.gov/'
memento = client.get_memento(url, exact=False, target_window=5 * 60)

This would correctly raise an error if the resulting memento was off by 10 minutes or by 1 day and 10 minutes, but incorrectly succeed if the memento was off by 1 day and 4 minutes.

@Mr0grog Mr0grog merged commit a3372fe into v0.2.x Oct 19, 2020
@Mr0grog Mr0grog deleted the target-window-is-more-broad-than-you-think branch October 19, 2020 22:15
Mr0grog added a commit that referenced this pull request Oct 19, 2020
This ports the v0.2.x fix from #53 to the v0.3.x release line.

The target_window parameter for `get_memento()` is supposed to limit how far off in time from the requested time you can get a memento for when the `exact` parameter is `False`. However, it only works correctly when the target is off by less than a day! (The scenarios we were originally concerned with in EDGI almost invariably were on the scale of a few hours, so I guess that's how this error snuck in.) If you set `exact=True` (the default), this bug wouldn’t be triggered.

We were checking the target offset by the number of seconds, irrespective of the additional number of days involved. This fixes the issue by checking by total_seconds, which converts the days into seconds and includes them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant