Louperivois added a comment.
Lets look at the example of Q192393 → Q213543 → Q7 on test.wikidata.
**Behavior of pywikibot :**
pywikibot.Page(site, "Q192393").exists() # True
pywikibot.Page(site, "Q192393").isRedirectPage() # True
pywikibot.Page(site, "Q192393").getRedirectTarget() # [[test:Q213543]]
print(page:=pywikibot.ItemPage(repo, "Q192393"), page.exists(),
page.isRedirectPage()) # [[test:Q192393]] False False
pywikibot.ItemPage(repo, "Q192393").exists() # False
pywikibot.ItemPage(repo, "Q192393").isRedirectPage() # True! (because
exists() has never been called on the instance)
pywikibot.ItemPage(repo, "Q192393").getRedirectTarget() # [[test:Q213543]]
(because super().getRedirectTarget() is called)
The inconstant return value of isRedirectPage is due to the implementation in
WikibaseEntity (_content is initialized when we call exists()) :
def isRedirectPage(self):
"""Return True if item is a redirect, False if not or not
existing."""
if hasattr(self, '_content') and not hasattr(self, '_isredir'):
self._isredir = self.id != self._content.get('id', self.id)
return self._isredir
return super().isRedirectPage()
**Behavior of API:**
If redirects=yes (default), the function getEntityRevision
<https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Wikibase/+/5f8b75c73cb6d43c6425a8928c782062790e15cc/repo/includes/Api/GetEntities.php#314>
catches the first redirection and try to resolve it (but not recursively,
setting redirects=no).
Test with redirects=no :
https://test.wikidata.org/w/api.php?action=wbgetentities&ids=Q192393%7CQ213543&redirects=no
(neither of them "exists" in the repository)
Test with redirects=yes :
https://test.wikidata.org/w/api.php?action=wbgetentities&ids=Q192393%7CQ213543&redirects=yes
**Suggestions**
- Refactor Wikibase.isRedirectPage() for consistant behavior
- Add documentation for Wikibase.exists() to make clear that page may exists
but not item.
TASK DETAIL
https://phabricator.wikimedia.org/T383267
EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/
_______________________________________________
pywikibot-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]