Page MenuHomePhabricator

OtherPageSaveError is raised instead of SpamfilterError
Closed, ResolvedPublic

Description

For some reason OtherPageSaveError is raised where I was excepting SpamfilterError.

>>> import pywikibot as pw;pw.Page(pw.Site(), 'user:framawiki/Brouillon3').put('https://bit.ly/test')
WARNING: No user is logged in on site wikipedia:fr
WARNING: No user is logged in on site wikipedia:fr
Logging in to wikipedia:fr as Framawiki
WARNING: API error spamblacklist: The text you wanted to save was blocked by the spam filter. This is probably caused by a link to a blacklisted external site. The following text is what triggered our spam filter: bit.ly/test
Traceback (most recent call last):
  File "pywikibot/page/__init__.py", line 117, in handle
    func(self, *args, **kwargs)
  File "pywikibot/page/__init__.py", line 1316, in _save
    watch=watch, bot=botflag, **kwargs)
  File "pywikibot/site/__init__.py", line 1340, in callee
    return fn(self, *args, **kwargs)
  File "pywikibot/site/__init__.py", line 5383, in editpage
    result = req.submit()
  File "pywikibot/data/api.py", line 2092, in submit
    raise APIError(**result['error'])
pywikibot.data.api.APIError: spamblacklist: The text you wanted to save was blocked by the spam filter. This is probably caused by a link to a blacklisted external site. The following text is what triggered our spam filter: bit.ly/test
[spamblacklist: {'matches': ['bit.ly/test']};
 help: See https://fr.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot/page/__init__.py", line 1383, in put
    **kwargs)
  File "pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot/page/__init__.py", line 1305, in save
    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
  File "pywikibot/page/__init__.py", line 138, in wrapper
    handle(func, self, *args, **kwargs)
  File "pywikibot/page/__init__.py", line 130, in handle
    raise pywikibot.OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[Utilisateur:Framawiki/Brouillon3]] failed:
spamblacklist: The text you wanted to save was blocked by the spam filter. This is probably caused by a link to a blacklisted external site. The following text is what triggered our spam filter: bit.ly/test
[spamblacklist: {'matches': ['bit.ly/test']};
 help: See https://fr.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]

Event Timeline

Change 586037 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] raise SpamfilterError with spamblacklist APIError

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

Change 586043 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] raise SpamfilterError with spamblacklist APIError

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

Xqt triaged this task as Medium priority.
Xqt added a subscriber: Dvorapa.

I made two alternate implemetations to solve this issue but I don't have any preferences.

Change 586043 abandoned by Xqt:
[IMPR] raise SpamfilterError with spamblacklist APIError

Reason:
in favour of https://gerrit.wikimedia.org/r/#/c/pywikibot/core/ /586037/

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

Besides, the term "spamfilter" looks only used in MW world by Flow, to describe the different spam fighters (blacklist, ...). "Spamblacklist" refers to Extension:SpamBlacklist.
Pywikibot describes its SpamfilterError as "MediaWiki spam filter detected a blacklisted URL".
Of what I understand SpamfilterError should be called SpamblacklistError. But renaming it would be complicated.

Of what I understand SpamfilterError should be called SpamblacklistError. But renaming it would be complicated.

Renamed it with that patch.

Change 586037 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] raise SpamblacklistError with spamblacklist APIError

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

Change 598876 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugix] replace SpamfilterError exceptions

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

Change 598876 merged by jenkins-bot:
[pywikibot/core@master] [bugix] replace SpamfilterError exceptions

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