jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Return exception instead of raising it
......................................................................
[FIX] Return exception instead of raising it
Instead of raising exceptions it should be returned so the data is set
to that exception. It also tests for that case.
It explicitly requires data after the request. One assertion is in the
thread after the lock is released and one assertion is in fetch and
happens also after the lock is released.
Bug: T94993
Change-Id: I955f1c91ae2dc31e404f05ee776d4184882c76f2
---
M pywikibot/comms/http.py
M pywikibot/comms/threadedhttp.py
M tests/http_tests.py
3 files changed, 10 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 4c2b2ec..044dba5 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -356,6 +356,7 @@
"""
request = _enqueue(uri, method, body, headers, **kwargs)
request._join() # wait for it
+ assert(request._data) # if there's no data in the answer we're in trouble
# Run the error handling callback in the callers thread so exceptions
# may be caught.
if default_error_handling:
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index e3c0e64..ced5329 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -306,7 +306,7 @@
headers=headers,
max_redirects=max_redirects - 1)
else:
- raise httplib2.RedirectLimit(
+ return httplib2.RedirectLimit(
"Redirected more times than redirection_limit allows.",
response, content)
@@ -539,6 +539,8 @@
finally:
if item.lock:
item.lock.release()
+ # if data wasn't set others might hang; but wait on lock
release
+ assert(item._data)
# Metaweb Technologies, Inc. License:
diff --git a/tests/http_tests.py b/tests/http_tests.py
index ff8337c..76ff447 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -191,6 +191,12 @@
self.assertEqual(r.response_headers['content-location'],
'http://www.gandi.net')
+ def test_maximum_redirects(self):
+ """Test that maximum redirect exception doesn't hang up."""
+ self.assertRaises(httplib2.RedirectLimit,
+ http.fetch,
+ uri='http://getstatuscode.com/300')
+
class ThreadedHttpTestCase(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/201696
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I955f1c91ae2dc31e404f05ee776d4184882c76f2
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits