Page MenuHomePhabricator

imagetransfer fails badly if specified page does not begin with correct namespace
Closed, ResolvedPublicBUG REPORT

Description

$ python pwb.py imagetransfer -family:wikipedia -lang:en "Joachim_Holst-Jensen_1923.jpg"
Traceback (most recent call last):
  File "pwb.py", line 157, in <module>
    run_python_file(fn, argv, argvu)
  File "pwb.py", line 67, in run_python_file
    exec(compile(source, filename, "exec"), main_mod.__dict__)
  File "scripts/imagetransfer.py", line 356, in <module>
    main()
  File "scripts/imagetransfer.py", line 353, in main
    bot.run()
  File "scripts/imagetransfer.py", line 273, in run
    {'title': page.title(), 'ns': pywikibot.Site().image_namespace()})
  File ".../pywikibot/data/api.py", line 856, in result
    p = PageGenerator.result(self, pagedata)
  File ".../pywikibot/data/api.py", line 840, in result
    update_page(p, pagedata)
  File ".../pywikibot/data/api.py", line 996, in update_page
    "Page %s has neither 'pageid' nor 'missing' attribute" % pagedict['title'])
AssertionError: Page Joachim Holst-Jensen 1923.jpg has neither 'pageid' nor 'missing' attribute
<type 'exceptions.AssertionError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort

Version: core-(2.0)
Severity: normal

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:39 AM
bzimport set Reference to bz68659.
bzimport added a subscriber: Unknown Object (????).

It also fails quite badly if the file doesnt exist.

$ python pwb.py imagetransfer -family:wikipedia -lang:en "File:Joachim_Holst-Jensen_1923"
------------------------------------------------------------
0. Found image: [[File:Joachim Holst-Jensen 1923]]
============================================================
Traceback (most recent call last):
  File "pwb.py", line 157, in <module>
    run_python_file(fn, argv, argvu)
  File "pwb.py", line 67, in run_python_file
    exec(compile(source, filename, "exec"), main_mod.__dict__)
  File "scripts/imagetransfer.py", line 356, in <module>
    main()
  File "scripts/imagetransfer.py", line 353, in main
    bot.run()
  File "scripts/imagetransfer.py", line 289, in run
    if imagelist[todo].fileIsShared():
  File ".../pywikibot/page.py", line 1827, in fileIsShared
    return self.fileUrl().startswith(
  File ".../pywikibot/page.py", line 1803, in fileUrl
    self._imageinfo = self.site.loadimageinfo(self)
  File ".../pywikibot/site.py", line 1445, in loadimageinfo
    if history else pageitem['imageinfo'][0])
KeyError: 'imageinfo'
<type 'exceptions.KeyError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort

It also fails if no arguments are given at all

$ python pwb.py imagetransfer -family:wikipedia -lang:en 
Traceback (most recent call last):
  File "pwb.py", line 157, in <module>
    run_python_file(fn, argv, argvu)
  File "pwb.py", line 67, in run_python_file
    exec(compile(source, filename, "exec"), main_mod.__dict__)
  File "scripts/imagetransfer.py", line 356, in <module>
    main()
  File "scripts/imagetransfer.py", line 353, in main
    bot.run()
  File "scripts/imagetransfer.py", line 273, in run
    {'title': page.title(), 'ns': pywikibot.Site().image_namespace()})
  File ".../pywikibot/data/api.py", line 883, in result
    p = PageGenerator.result(self, pagedata)
  File ".../pywikibot/data/api.py", line 867, in result
    update_page(p, pagedata)
  File ".../pywikibot/data/api.py", line 1023, in update_page
    "Page %s has neither 'pageid' nor 'missing' attribute" % pagedict['title'])
AssertionError: Page  has neither 'pageid' nor 'missing' attribute
<type 'exceptions.AssertionError'>

imagetransfer.py now shows a help message when called with no arguments.
However, it still fails if the specified page does not exist or does not begin with the correct namespace.

Change 162781 had a related patch set uploaded by Mpaa:
Bug 68659-imagetransfer fails if file doesnt exist

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

I do not think this is a bug: the specified page does not exist or does not begin with the correct namespace.

Input page does not necessarily belongs to File: namespace.

"If pagename is an image description page, offers to copy the image to the
target site. If it is a normal page, it will offer to copy any of the images
used on that page, or if the -interwiki argument is used, any of the images
used on a page reachable via interwiki links."

Now it fails gracefully, however.

Change 162781 had a related patch set uploaded (by XZise):
imagetransfer fails if file doesnt exist

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

Patch-For-Review

jayvdb set Security to None.

Change 162781 abandoned by Mpaa:
[FEAT] Imagetransfer: Rewritten file selection

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

Aklapper triaged this task as Low priority.Feb 4 2022, 8:07 PM
Aklapper changed the subtype of this task from "Task" to "Bug Report".

The first issue is solved:

D:\pwb\GIT\core>pwb.py -simulate imagetransfer -family:wikipedia -lang:en "Joachim_Holst-Jensen_1923.jpg"
WARNING: Page [[en:Joachim Holst-Jensen 1923.jpg]] does not exist on wikipedia:en.

1 skip operation
Execution time:
Skip operation time: 0.0 seconds
Script terminated successfully.

The second issue is solved:

D:\pwb\GIT\core>pwb.py -simulate imagetransfer -family:wikipedia -lang:en "File:Joachim_Holst-Jensen_1923.jpg"
WARNING: Page [[en:File:Joachim Holst-Jensen 1923.jpg]] does not exist on wikipedia:en.

1 skip operation
Execution time:
Skip operation time: 0.0 seconds
Script terminated successfully.

The 3rd is also solved:

D:\pwb\GIT\core>pwb.py -simulate imagetransfer -family:wikipedia -lang:en
ERROR: Missing parameter "page".
and no other generator was defined.
Use -help for further information.

Therefore closing this.

Xqt claimed this task.