Page MenuHomePhabricator

test_create_short_link of page_tests.TestShortLink fails with strange APIError
Closed, ResolvedPublic

Description

test_create_short_link fails with APIError urlshortener-blocked: Blocked users can't make short URLs.

But neither pywikibot-test nor pywikibot-oauth user is blocked within wikimedia site farm.

https://ci.appveyor.com/project/Ladsgroup/pywikibot-g4xqx/builds/30506813/job/3pt2jdg6lbgmfoon

[00:20:46] ======================================================================
[00:20:46] ERROR: test_create_short_link (tests.page_tests.TestShortLink)
[00:20:46] Test create_short_link function.
[00:20:46] ----------------------------------------------------------------------
[00:20:46] Traceback (most recent call last):
[00:20:46]   File "c:\projects\pywikibot-g4xqx\tests\page_tests.py", line 1192, in test_create_short_link
[00:20:46]     self.assertEqual(p1.create_short_link(), 'https://w.wiki/3Cy')
[00:20:46]   File "c:\projects\pywikibot-g4xqx\pywikibot\page.py", line 2254, in create_short_link
[00:20:46]     link = wiki.create_short_link(url)
[00:20:46]   File "c:\projects\pywikibot-g4xqx\pywikibot\site.py", line 1368, in callee
[00:20:46]     return fn(self, *args, **kwargs)
[00:20:46]   File "c:\projects\pywikibot-g4xqx\pywikibot\site.py", line 7548, in create_short_link
[00:20:46]     data = req.submit()
[00:20:46]   File "c:\projects\pywikibot-g4xqx\pywikibot\data\api.py", line 2085, in submit
[00:20:46]     raise APIError(**result['error'])
[00:20:46] APIError: urlshortener-blocked: Blocked users can't make short URLs. [help:See https://meta.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.]
[00:20:46]

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald Transcript

Is this in API or in our short link implementation?

Is this in API or in our short link implementation?

This is an API exception.

Is this in API or in our short link implementation?

This is an API exception.

Yeah, but do we use/provide the correct user? Is this really done under Pywikibot-* account?

GIPBE duly granted.

Great, thanks!

Xqt claimed this task.
Xqt removed Xqt as the assignee of this task.
Xqt removed a project: Upstream.

There must be another remaining issue.

@revi Have you granted the rights for all Travis/AppVeyor IPs? Or just those mentioned in the request? (I don't know, how it works, just better to ask)

Only two accounts (pywikibot-oauth and pywikibot-test) were granted GIPBE, and you must authenticate as one of the accounts to enjoy the IP Block exemption. We are not willing to unblock Amazon Web Services/Google Cloud/Microsoft Azure/etc etc IPs as they are frequently abused for provisioning VPN node to vandalize Wikipedia.

Only two accounts (pywikibot-oauth and pywikibot-test) were granted GIPBE, and you must authenticate as one of the accounts to enjoy the IP Block exemption. We are not willing to unblock Amazon Web Services/Google Cloud/Microsoft Azure/etc etc IPs as they are frequently abused for provisioning VPN node to vandalize Wikipedia.

Yeah, I meant if you granted GIPBE correctly as it still seems Pywikibot-test/Pywikibot-oauth are blocked too on some Travis/AppVeyor IP ranges (not all of them, but some of them for sure).

GIPBEs does not exempt you from the local blocks, check if there is local block against that IP on the project you are editing.

Currently it fails on enwiki and testwiki.

Change 571695 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [tests] Show additional informations with "urlshortener-blocked" APIError

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

Change 571695 merged by jenkins-bot:
[pywikibot/core@master] [tests] Show additional informations with "urlshortener-blocked" APIError

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

@Anomie, @Legoktm, @SQL : Can you help in this matter and grant local ipblock exempt for pywikibot-test and pywikibot-oauth at en-wiki please. WP:UTRS does no work in that case for a foreign user.

Change 571730 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] userinfo is required for user name or IP no

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

Change 571730 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] userinfo is required for user name or IP no

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

No, site.user() is empty even when logged in. self.site.username() still retrieves Pywikibot-test

$ python pwb.py shell
Welcome to the Pywikibot interactive shell!
>>> s=pywikibot.Site()
>>> s.user()
>>> s.username()
'DvorapaBot'

No, site.user() is empty even when logged in. self.site.username() still retrieves Pywikibot-test

def user(self):
    """Return the currently-logged in bot username, or None."""
    if self.logged_in():
        return self.username()
    else:
        return None

Try site.logged_in()

Then self.logged_in() does not work as expected:

$ python pwb.py login
Logged in on wikipedia:cs as DvorapaBot.
$ python pwb.py shell
Welcome to the Pywikibot interactive shell!
>>> s=pywikibot.Site()
>>> s.logged_in()
False

Does it have something in common with those warnings all over tests:

WARNING: No user is logged in on site wikipedia:en
skipped 'TestUserWatchedPages: Not able to login to wikipedia:en'

?

I guess user attribute must be set forthe test class to force login. After global blocks for several IPs used by test runners the account must be logged in for this api method. Surely without block this test will work I think.

Change 571919 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Force login for TestShortLink

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

Change 571919 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Force login for TestShortLink

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

Xqt claimed this task.
Dvorapa reopened this task as Open.EditedMar 20 2020, 4:42 PM

Still failing on test:wp, nb:wp, ar:wikt and uk:wowwiki. Tests currently prints meta:meta username. Could we print also test:wp username and default site username to compare?

Change 585068 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [tests] Use meta for TestShortLink

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

Change 585068 merged by jenkins-bot:
[pywikibot/core@master] [tests] Use meta for TestShortLink

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

Shouldn't we login to meta in the create_shortlink method itself? Rather than workaround it in tests?

It seems it works correctly, but weirdly enough the test fails (failed). There might be some issue with test initiation.

Shouldn't we login to meta in the create_shortlink method itself? Rather than workaround it in tests?

I thought that unified global account are logged in automatically. Seems that isn't here, probably due to login/logout tests or something else. I never saw this failure locally. I think for a logged in bot it works independently of the site. But here in test environment it does not. Probable the test class can be switched to DefaultSiteTestCase but with additional login at meta within setUpClass.

It seems it works correctly, but weirdly enough the test fails (failed). There might be some issue with test initiation.

The only difference is the system site package; no idea what this means for this failing.

Shouldn't we login to meta in the create_shortlink method itself? Rather than workaround it in tests?

I thought that unified global account are logged in automatically. Seems that isn't here, probably due to login/logout tests or something else. I never saw this failure locally. I think for a logged in bot it works independently of the site. But here in test environment it does not. Probable the test class can be switched to DefaultSiteTestCase but with additional login at meta within setUpClass.

Okay, what if tests are "unified global account are logged in automatically" in the beginning of tests (initiation of Meta Class?), then login_logout test will logout all of them successfully and finally they are logged out here? Perhaps we should try to reinitiate Meta Class/Meta Class'es Site() after login_logout test?

Okay, what if tests are "unified global account are logged in automatically" in the beginning of tests (initiation of Meta Class?), then login_logout test will logout all of them successfully and finally they are logged out here? Perhaps we should try to reinitiate Meta Class after login_logout test?

There is another issue: At Travis we run up to 5 jobs simultaneously. With each logout all current jobs are logged out and need to re-login. Parallel jobs saves test time but it can cause failures. Probably we should run login/logout tests on Appveyor only because the we have only 1 job running at the same time there.

Okay, what if tests are "unified global account are logged in automatically" in the beginning of tests (initiation of Meta Class?), then login_logout test will logout all of them successfully and finally they are logged out here? Perhaps we should try to reinitiate Meta Class after login_logout test?

There is another issue: At Travis we run up to 5 jobs simultaneously. With each logout all current jobs are logged out and need to re-login. Parallel jobs saves test time but it can cause failures. Probably we should run login/logout tests on Appveyor only because the we have only 1 job running at the same time there.

Good point. Another option (imo worse) would be to run Travis test the same as AppVeyor. And finally DefaultSiteTestCase could somehow check login status and relogin if it detects there is an issue.

Dvorapa lowered the priority of this task from High to Medium.Apr 1 2020, 11:52 AM

(not failing tests currently, but weird behavior of Travis tests)

Dvorapa raised the priority of this task from Medium to High.Apr 5 2020, 4:57 PM

With the patch the source page changed (to non-existent) and after tests were fixed, it started to fail again

Change 587310 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [test] Make sure test user is logged in on meta:meta

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

Change 587310 merged by jenkins-bot:
[pywikibot/core@master] [test] Make sure test user is logged in on meta:meta

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