My first experience with pywikibot, downloaded core, i wanted to change a few pages. Immediately ran into an error when trying to set a page's text to empty. The error message was unhelpful, but I dug through the source and found the issue. I'd like to suggest that 2 things:
1. Setting a page's text to be empty should be allowed
2. If not, at least the error should be fixed to actually show the correct error, explained below.
Here is an example script, and the error when running it
import pywikibot site = pywikibot.Site() page = pywikibot.Page(site, "MediaWiki:Lastmodifiedat") page.text = "" page.save()
Logging in to ianwiki:en as Ian Kelling Traceback (most recent call last): File "pwb.py", line 143, 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/iansetup.py", line 5, in <module> page.save() File "/a/opt/pywikibot/pywikibot/page.py", line 858, in save **kwargs) File "/a/opt/pywikibot/pywikibot/page.py", line 884, in _save raise pywikibot.PageNotSaved("%s: %s" % (link, err)) pywikibot.exceptions.PageNotSaved CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort <class 'pywikibot.exceptions.PageNotSaved'>
The cause is in site.py, in def editpage, line 2699:
if not text: raise Error("editpage: no text to be saved")
This error should be shown instead of the one that is actually shown.
It has been done intentionally and I think it's a right thing to do, you can bypass it by saving a dot instead of nothing
Best
On Wed, May 28, 2014 at 9:13 AM, Ian Kelling ian@iankelling.org wrote:
My first experience with pywikibot, downloaded core, i wanted to change a few pages. Immediately ran into an error when trying to set a page's text to empty. The error message was unhelpful, but I dug through the source and found the issue. I'd like to suggest that 2 things:
Setting a page's text to be empty should be allowed
If not, at least the error should be fixed to actually show the
correct error, explained below.
Here is an example script, and the error when running it
import pywikibot site = pywikibot.Site() page = pywikibot.Page(site, "MediaWiki:Lastmodifiedat") page.text = "" page.save()
Logging in to ianwiki:en as Ian Kelling Traceback (most recent call last): File "pwb.py", line 143, 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/iansetup.py", line 5, in <module> page.save() File "/a/opt/pywikibot/pywikibot/page.py", line 858, in save **kwargs) File "/a/opt/pywikibot/pywikibot/page.py", line 884, in _save raise pywikibot.PageNotSaved("%s: %s" % (link, err)) pywikibot.exceptions.PageNotSaved CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort <class 'pywikibot.exceptions.PageNotSaved'>
The cause is in site.py, in def editpage, line 2699:
if not text: raise Error("editpage: no text to be saved")
This error should be shown instead of the one that is actually shown.
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
Amir Ladsgroup ladsgroup@gmail.com writes:
It has been done intentionally and I think it's a right thing to do, you can bypass it by saving a dot instead of nothing
Best
A dot is significantly different than nothing in many cases, including the page I in my example, MediaWiki:Lastmodifiedat. I should be able to do it, perhaps I should need to pass something like force=true, but it is a perfectly valid thing to do.
- Ian
I checked compat and there is force parameter implemented but It's completely useless (it hasn't used in code) Can you open a bug for it in bugzilla? I'll work on it.
Best
On Wed, May 28, 2014 at 7:11 PM, Ian Kelling ian@iankelling.org wrote:
Amir Ladsgroup ladsgroup@gmail.com writes:
It has been done intentionally and I think it's a right thing to do, you
can bypass it by saving a dot instead of
nothing
Best
A dot is significantly different than nothing in many cases, including the page I in my example, MediaWiki:Lastmodifiedat. I should be able to do it, perhaps I should need to pass something like force=true, but it is a perfectly valid thing to do.
- Ian
Amir Ladsgroup ladsgroup@gmail.com writes:
I checked compat and there is force parameter implemented but It's completely useless (it hasn't used in code) Can you open a bug for it in bugzilla? I'll work on it.
Best
Awesome. I filed a bug here https://bugzilla.wikimedia.org/show_bug.cgi?id=65971.
On Wed, May 28, 2014 at 11:43 AM, Ian Kelling ian@iankelling.org wrote:
My first experience with pywikibot, downloaded core, i wanted to change a few pages. Immediately ran into an error when trying to set a page's text to empty. The error message was unhelpful, but I dug through the source and found the issue. I'd like to suggest that 2 things:
Setting a page's text to be empty should be allowed
If not, at least the error should be fixed to actually show the
correct error, explained below.
Here is an example script, and the error when running it
import pywikibot site = pywikibot.Site() page = pywikibot.Page(site, "MediaWiki:Lastmodifiedat") page.text = "" page.save()
Logging in to ianwiki:en as Ian Kelling Traceback (most recent call last): File "pwb.py", line 143, 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/iansetup.py", line 5, in <module> page.save() File "/a/opt/pywikibot/pywikibot/page.py", line 858, in save **kwargs) File "/a/opt/pywikibot/pywikibot/page.py", line 884, in _save raise pywikibot.PageNotSaved("%s: %s" % (link, err)) pywikibot.exceptions.PageNotSaved CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort <class 'pywikibot.exceptions.PageNotSaved'>
The cause is in site.py, in def editpage, line 2699:
if not text: raise Error("editpage: no text to be saved")
This error should be shown instead of the one that is actually shown.
Indeed it should be shown. The problem is that this exception is caught in Page._save and not re-raised - instead, a different Exception is raised, which makes it harder to debug the code.
if Site.editpage continues to prevent saving an empty item (unless forced to), Site.editpage should throw the exception PageNotSaved("editpage: no text to be saved") and that exception with its backtrace should be left alone.