Page MenuHomePhabricator

site_detect_tests fails with AttributeError in constructor of MWSite
Closed, ResolvedPublic

Description

site_detect_tests fails for StandardVersionSiteTestCase.test_wikichristian with
AttributeError: 'MWSite' object has no attribute 'private_wiki'
in constructor of MWSite. (travis)

Event Timeline

Xqt triaged this task as Medium priority.Mar 13 2017, 3:49 PM
Xqt updated the task description. (Show Details)

Digging deeper shows the warning:

tests/site_detect_tests.py::StandardVersionSiteTestCase::test_wikichristian WARNING: Http response status 500
FAILED

which means request.status is not in (200, 207) but ServerError('Internal Server Error') for isn't raised by MWSite constructor for request.status==500

Dalba subscribed.
This comment was removed by Dalba.
Dalba removed Dalba as the assignee of this task.Mar 13 2017, 4:59 PM

I thought I knew what is causing this, but it turned out that it was not it. :)

private_wiki is not set because _parse_post_117 method is getting a server error status from the server and ignores it. We should check for server errors inside _parse_post_117, just the way we do in MWSite.__init__.

To be more specific, inside _parse_post_117, when the response.status is 500, response.content.strip().lstrip('\uFEFF') will be an empty string, therefore json.loads(content) will fail with JSONDecodeError. This error is ignored by the try-except statement that is wrapping _parse_post_117.

Change 349156 had a related patch set uploaded (by Dalba):
[pywikibot/core@master] site_detect.py: Check the response in _parse_post_117 for server errors

https://gerrit.wikimedia.org/r/349156

Change 349156 merged by jenkins-bot:
[pywikibot/core@master] site_detect.py: Check the response in _parse_post_117 for server errors

https://gerrit.wikimedia.org/r/349156

Dalba claimed this task.
Dalba reopened this task as Open.EditedMay 31 2017, 6:24 PM

This happened again in https://travis-ci.org/wikimedia/pywikibot-core/jobs/237649587#L4782

It seems that the fetch inside the _parse_post_117 method is raising some kind of exception...

I'll send a patch for review.

Change 356432 had a related patch set uploaded (by Dalba; owner: Dalba):
[pywikibot/core@master] MWSite.init: Re-raise the RequestException of _parse_post_117

https://gerrit.wikimedia.org/r/356432

Change 356432 merged by jenkins-bot:
[pywikibot/core@master] MWSite.init: Re-raise the RequestException of _parse_post_117

https://gerrit.wikimedia.org/r/356432