From 541fc77f9d6b1a73386629ec3a11a3cdbcccf8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilfredo=20Rafael=20Rodr=C3=ADguez=20Hern=C3=A1ndez?= Date: Sat, 6 Jun 2026 16:50:52 -0300 Subject: [PATCH] Fix uncaught SectionError when a nomination redirects to a section A nomination subpage that redirects to a section (a malformed "#REDIRECT [[Target#Section]]") made getRedirectTarget() return a page that still carried the section on pywikibot versions before 9.3, which added the 'ignore_section' parameter. The subsequent Page.get() then raised an uncaught SectionError that aborted the whole bot run (reported for the "File:A polarized light micrograph of physiological saline crystals.jpg" nomination). Treat a redirect that points to a section as invalid: skip the nomination and report it via ask_for_help(), consistently with the handling of other invalid redirects. --- fpc.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fpc.py b/fpc.py index 5aaabee..f613112 100644 --- a/fpc.py +++ b/fpc.py @@ -3994,6 +3994,24 @@ def _resolve_nomination_subpage_redirect( f"contains an invalid redirect. {PLEASE_FIX_HINT}" ) return None + # A nomination subpage must redirect to a whole page, never to a + # section. A malformed "#REDIRECT [[Target#Section]]" yields a + # target that still carries the section on pywikibot versions before + # 9.3, which added the 'ignore_section' parameter to + # getRedirectTarget(). Calling Page.get() on such a target later + # raises an uncaught SectionError and aborts the whole bot run. + # Treat a redirect that points to a section as invalid instead. + if subpage.section(): + error( + f"Error - nomination redirect '{old_name}' points to a " + "section, ignoring." + ) + ask_for_help( + f"The nomination subpage [[{old_name}]] redirects to a " + "section of a page rather than to a page itself, " + f"which the bot cannot process. {PLEASE_FIX_HINT}" + ) + return None new_name = subpage.title() out(f"Nomination '{old_name}' has been renamed to '{new_name}'") redirects.append((old_name, new_name))