Fix uncaught SectionError when a nomination redirects to a section#48
Open
wilfredor wants to merge 1 commit into
Open
Fix uncaught SectionError when a nomination redirects to a section#48wilfredor wants to merge 1 commit into
wilfredor wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FPCBot crashed with an uncaught
SectionError, aborting the entire run:(reported by FPCBot on the FPC talk page, 6 June 2026).
Root cause
The nomination subpage was a redirect pointing to a section (a malformed
#REDIRECT [[Target#Section]]). In_resolve_nomination_subpage_redirect(),subpage.getRedirectTarget()returned aPagethat still carried that section fragment: theignore_sectionparameter (which by default strips the section from the target) was only added togetRedirectTarget()in pywikibot 9.3. The candidate's page therefore had a section, and the laterPage.get()(reached viafiltered_content()→was_cancelled()duringpark) raised the uncaughtSectionError.Fix
A nomination subpage must redirect to a whole page, never to a section. The fix detects a redirect whose resolved target carries a section and treats it as an invalid redirect: it skips the nomination and reports it via
ask_for_help(), consistently with how other invalid redirects are already handled. It uses onlyPage.section(), so it is independent of the pywikibot version.Testing
SectionErroroffline (constructing aPagewith the section fragment raises it inPage.get(), before any network call)._resolve_nomination_subpage_redirect():return None) and flagged viaask_for_help(), instead of crashing the run;python -m py_compile fpc.pypasses.