Skip to content

Fix uncaught SectionError when a nomination redirects to a section#48

Open
wilfredor wants to merge 1 commit into
Zitrax:masterfrom
wilfredor:fix-section-redirect-crash
Open

Fix uncaught SectionError when a nomination redirects to a section#48
wilfredor wants to merge 1 commit into
Zitrax:masterfrom
wilfredor:fix-section-redirect-crash

Conversation

@wilfredor
Copy link
Copy Markdown

Problem

FPCBot crashed with an uncaught SectionError, aborting the entire run:

pywikibot.exceptions.SectionError: 'File:A polarized light micrograph of physiological saline crystals.jpg' is not a valid section of Commons:Featured picture candidates/File:A polarized light micrograph of physiological saline crystals.jpg

(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 a Page that still carried that section fragment: the ignore_section parameter (which by default strips the section from the target) was only added to getRedirectTarget() in pywikibot 9.3. The candidate's page therefore had a section, and the later Page.get() (reached via filtered_content()was_cancelled() during park) raised the uncaught SectionError.

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 only Page.section(), so it is independent of the pywikibot version.

Testing

  • Reproduced the exact SectionError offline (constructing a Page with the section fragment raises it in Page.get(), before any network call).
  • Unit-tested _resolve_nomination_subpage_redirect():
    • a redirect pointing to a section is now skipped (return None) and flagged via ask_for_help(), instead of crashing the run;
    • a normal rename redirect (target without a section) still resolves correctly and records the rename.
  • python -m py_compile fpc.py passes.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant