Page MenuHomePhabricator

test_load_from_pageids_pipe_separated is failing on Travis
Closed, ResolvedPublic

Description

________ TestLoadPagesFromPageids.test_load_from_pageids_pipe_separated ________
self = <tests.site_tests.TestLoadPagesFromPageids testMethod=test_load_from_pageids_pipe_separated>
    def test_load_from_pageids_pipe_separated(self):
        """Test loading from comma-separated pageids."""
        pageids = '|'.join(str(page._pageid) for page in self.links)
        gen = self.site.load_pages_from_pageids(pageids)
>       for count, page in enumerate(gen, start=1):
tests/site_tests.py:2568: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/site.py:3148: in load_pages_from_pageids
    for sublist in itergroup(filter_unique(gen), groupsize):
pywikibot/tools/__init__.py:637: in itergroup
    for item in iterable:
pywikibot/tools/__init__.py:876: in filter_unique
    for item in iterable:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.0 = <list_iterator object at 0x7f12de6724a8>
>   gen = (str(int(p)) for p in pageids if int(p) > 0)
E   ValueError: invalid literal for int() with base 10: ''
pywikibot/site.py:3139: ValueError

See: https://travis-ci.org/wikimedia/pywikibot-core/jobs/184925687#L1902

Event Timeline

Change 328044 had a related patch set uploaded (by Magul):
Change pageids validation to more error resilient

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

Change 337348 had a related patch set uploaded (by Dalba):
site.py: load_pages_from_pageids do not fail on empty string

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

Change 337348 merged by jenkins-bot:
[pywikibot/core] load_pages_from_pageids: do not fail on empty string

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

Change 328044 had a related patch set uploaded (by Magul):
Change pageids validation to more error resilient

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

@Dalba @Xqt @Magul: Should this patch be abandoned with the merging of https://gerrit.wikimedia.org/r/337348?

@Dalba @Xqt @Magul: Should this patch be abandoned with the merging of https://gerrit.wikimedia.org/r/337348?

Apparently that patch is pursuing another goal: "Make pageids validation's error more descriptive". But personally, I don't find think it's worth the added complexity and it's not common for users to pass something other than valid pageids to load_pages_from_pageids. In the rare case that they do I find the ValueError: invalid literal for int() with base 10: '' descriptive enough.

@Dalba @Xqt @Magul: Should this patch be abandoned with the merging of https://gerrit.wikimedia.org/r/337348?

Apparently that patch is pursuing another goal: "Make pageids validation's error more descriptive". But personally, I don't find think it's worth the added complexity and it's not common for users to pass something other than valid pageids to load_pages_from_pageids. In the rare case that they do I find the ValueError: invalid literal for int() with base 10: '' descriptive enough.

A quick fix might be to wrap the gen = call in a try and then catch any ValueError and replace it by something more descriptive?

A quick fix might be to wrap the gen = call in a try and then catch any ValueError and replace it by something more descriptive?

On the other hand then one would have to parse the original error message to get the offending string out. You are right that it doesn't seem worth it. I would abandon that patch and mark this task as resolved.

Change 328044 abandoned by Xqt:
[pywikibot/core@master] Make pageids validation's error more descriptive

Reason:
seems T153592 is solved already

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