Page MenuHomePhabricator

several tests fails due to invalid extension
Closed, ResolvedPublic

Description

There is a redirect File:Invalid.ext on test wiki in File namespace.
randompages() tries to upcast to a FilePage but fails due to invalid extension

13:19:45 ======================================================================
13:19:45 ERROR: test_redirects (tests.site_generators_tests.SiteRandomTestCase)
13:19:45 Test site.randompages() with redirects.
13:19:45 ----------------------------------------------------------------------
13:19:45 Traceback (most recent call last):
13:19:45   File "/src/tests/site_generators_tests.py", line 1579, in test_redirects
13:19:45     for rndpage in mysite.randompages(total=5, redirects=True):
13:19:45   File "/usr/lib/python3.6/_collections_abc.py", line 317, in __next__
13:19:45     return self.send(None)
13:19:45   File "/src/pywikibot/tools/collections.py", line 275, in send
13:19:45     return next(self._started_gen)
13:19:45   File "/src/pywikibot/data/api/_generators.py", line 619, in generator
13:19:45     yield from self._extract_results(resultdata)
13:19:45   File "/src/pywikibot/data/api/_generators.py", line 563, in _extract_results
13:19:45     result = self.result(item)
13:19:45   File "/src/pywikibot/data/api/_generators.py", line 722, in result
13:19:45     p = pywikibot.FilePage(p)
13:19:45   File "/src/pywikibot/page/_filepage.py", line 62, in __init__
13:19:45     f'{title!r} does not have a valid extension '
13:19:45 ValueError: 'File:Invalid.ext' does not have a valid extension (djvu, flac, gif, jpeg, jpg, mid, midi, mp3, mpeg, mpg, oga, ogg, ogv, opus, pdf, png, stl, svg, tif, tiff, wav, webm, webp, xcf).
13:19:45

https://integration.wikimedia.org/ci/job/pywikibot-core-tox-deeptest-py36-docker/2756/console

Maybe the redirect status should be checked first before the extension is checked. Or can we have a Page object in namespace 6 which is not a FilePage?

We have a similar problem with wanted files generator:

D:\pwb\GIT\core>pwb -site:wowwiki:uk pagegenerators_tests -v TestWantedFactoryGenerator.test_wanted_files
tests: max_retries reduced from 15 to 1
test_wanted_files (__main__.TestWantedFactoryGenerator.test_wanted_files)
Test wantedfiles generator. ... ERROR

======================================================================
ERROR: test_wanted_files (__main__.TestWantedFactoryGenerator.test_wanted_files)
Test wantedfiles generator.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\pwb\GIT\core\tests\pagegenerators_tests.py", line 1437, in test_wanted_files
    for page in self._generator_with_tests():
  File "D:\pwb\GIT\core\tests\pagegenerators_tests.py", line 1424, in _generator_with_tests
    pages = list(gen)
            ^^^^^^^^^
  File "<frozen _collections_abc>", line 330, in __next__
  File "D:\pwb\GIT\core\pywikibot\tools\collections.py", line 275, in send
    return next(self._started_gen)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\pwb\GIT\core\pywikibot\data\api\_generators.py", line 619, in generator
    yield from self._extract_results(resultdata)
  File "D:\pwb\GIT\core\pywikibot\data\api\_generators.py", line 563, in _extract_results
    result = self.result(item)
             ^^^^^^^^^^^^^^^^^
  File "D:\pwb\GIT\core\pywikibot\data\api\_generators.py", line 722, in result
    p = pywikibot.FilePage(p)
        ^^^^^^^^^^^^^^^^^^^^^
  File "D:\pwb\GIT\core\pywikibot\page\_filepage.py", line 61, in __init__
    raise ValueError(
ValueError: "Файл:' .. img filename .. '" does not have a valid extension (flac, gif, ico, jpeg, jpg, mkv, mov, mp3, mp4, odm, oga, ogg, ogv, pdf, png, svg, wav, webm, webp).

----------------------------------------------------------------------
Ran 1 test in 2.877s

FAILED (errors=1)

D:\pwb\GIT\core>

This behaviour was introduced with T345786 (rPWBC8c86bcb)

Event Timeline

Xqt renamed this task from site_generators_tests.SiteRandomTestCase.test_redirects fails due to invalid exception to several tests fails due to invalid extension .Sep 20 2023, 3:46 PM
Xqt updated the task description. (Show Details)
Xqt changed the task status from Open to In Progress.Sep 20 2023, 5:01 PM
Xqt claimed this task.

Change 959331 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [bugfix] upcast to FilePage for a proper extension only

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

Xqt triaged this task as High priority.Sep 20 2023, 6:21 PM

Change 959331 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] upcast to FilePage for a proper extension only

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