Page MenuHomePhabricator

Handle InvalidTitleError in Page.text property
Open, LowPublicBUG REPORT

Description

Steps to replicate the issue:

>>> site = pywikibot.Site('hu', 'wikipedia')
>>> page=pywikibot.Page(site, 'Vita:WP:AZ')
>>> page.text
pywikibot.exceptions.InvalidTitleError: The (non-)talk page of 'Vita:WP:AZ' is a valid title in another namespace.

What happens?: WP: used to be a standard redirect to project pages, technically in main namespace. Now it is an alias for Project: namespace.
I watched hu:WP:AZ when it was in article namespace, and its talk page was 'Vita:WP:AZ'. Now this is ambigous. The error is in MediaWiki config, however, Pywikibot should catch it.

What should have happened instead?:
I don't know. As far as I understand, Page.text is designed to return a string under any circumstances and never raise an error. But to return an empty string for an invalid title would be strange, and anyway, itt will fail on saving, so work with text is senseless.

Software version: 2.0+

Other information (browser name/version, screenshots, etc.):
In the source code of Page.text there is a comment: "# TODO: what other exceptions might be returned?" Now the answer is here. :-)