jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1057340?usp=email )
Change subject: [fix] Only add lang links to page._langlinks if present in family file ......................................................................
[fix] Only add lang links to page._langlinks if present in family file
Language links retrieved via API may have links which aren't present in the family file.
Bug: T371107 Change-Id: I9e850f2f02eac3208bc1361eb6ff76d4589f2575 --- M pywikibot/data/api/_generators.py 1 file changed, 20 insertions(+), 5 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api/_generators.py b/pywikibot/data/api/_generators.py index de6f011..69ca560 100644 --- a/pywikibot/data/api/_generators.py +++ b/pywikibot/data/api/_generators.py @@ -20,7 +20,12 @@ import pywikibot from pywikibot import config from pywikibot.backports import Callable, Iterable -from pywikibot.exceptions import Error, InvalidTitleError, UnsupportedPageError +from pywikibot.exceptions import ( + Error, + InvalidTitleError, + UnknownSiteError, + UnsupportedPageError, +) from pywikibot.site import Namespace from pywikibot.tools import deprecated from pywikibot.tools.collections import GeneratorWrapper @@ -936,10 +941,20 @@
def _update_langlinks(page, langlinks) -> None: - """Update page langlinks.""" - links = {pywikibot.Link.langlinkUnsafe(link['lang'], link['*'], - source=page.site) - for link in langlinks} + """Update page langlinks. + + .. versionadded:: 9.3 + only add a language link if it is found in the family file. + + :meta public: + """ + links = set() + for langlink in langlinks: + with suppress(UnknownSiteError): + link = pywikibot.Link.langlinkUnsafe(langlink['lang'], + langlink['*'], + source=page.site) + links.add(link)
if hasattr(page, '_langlinks'): page._langlinks |= links
pywikibot-commits@lists.wikimedia.org