-
Notifications
You must be signed in to change notification settings - Fork 648
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 failing specs due to new wikipageviews API behavior when no data available #5513
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,13 +101,23 @@ def parse_results(response) | |
return data['items'] if data['items'] | ||
# As of October 2017, the data type is https://www.mediawiki.org/wiki/HyperSwitch/errors/not_found | ||
return no_results if %r{errors/not_found}.match?(data['type']) | ||
return no_results if no_data_available_response?(data) | ||
raise PageviewApiError, response | ||
end | ||
|
||
def no_results | ||
{} | ||
end | ||
|
||
# As of October 2023, we started to see 404 not found responses with about:blank type | ||
# and a specific detail when handling requests for which no data is available | ||
def no_data_available_response?(response) | ||
no_data_avialable_detail = 'The date(s) you used are valid, but we either do not have data '\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think relying on the exact 'detail' message here is going to be too fragile. Is this always the message when type is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first glance, I thought that |
||
'for those date(s), or the project you asked for is not loaded yet.'\ | ||
' Please check documentation for more information.' | ||
response['status'] == 404 && response['detail'] == no_data_avialable_detail | ||
end | ||
|
||
def wiki_url_param | ||
# Wikidata works with either "www.wikidata" or just "wikidata", but not ".wikidata" | ||
@wiki.language ? "#{@wiki.language}.#{@wiki.project}" : @wiki.project | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,8 @@ | |
let(:title) { 'Voyages,_aventures_et_combats/Chapitre_18' } | ||
let(:subject) { described_class.new(article).average_views } | ||
|
||
before { travel_to Date.new(2023, 10, 18) } | ||
|
||
Comment on lines
+162
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to add this because it looks like I visited the site yesterday so I broke the spec.
This way it should be more robust. |
||
it 'returns 0' do | ||
VCR.use_cassette 'wiki_pageviews/404_handling' do | ||
expect(subject).to eq(0) | ||
|
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.
Are there still also requests that return this error type, or did all 404's become
about:blank
?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.
Maybe it would be better to just rely on the 404 status and ignore
type
altogether? I imagine that any case of a 404 should be treated the same way by the Dashboard, and it looks like that's the only error mode that we've ever handled anyway.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.
hmm good point. I wasn't able to reproduce any request returning
https://www.mediawiki.org/wiki/HyperSwitch/errors/not_found
astype
. If I understand correctly, this request should be one of those that returned that type. So I think that your point about only relying on the 404 status makes total sense. Done on 41a142f. Two specs are failing but I guess those are flaky tests?