jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1326287?usp=email )

Change subject: api: Forward request context while waiting
......................................................................

api: Forward request context while waiting

Allow Request.wait to accept and forward timeout context to the shared
waiting implementation. This preserves its API error reset while ensuring
exhausted retries report the site and URI.

Bug: T434974
Change-Id: Ia67f91047bf8c4b17d9c9279fd412fe4a5785454
---
M pywikibot/data/api/_requests.py
M tests/api_tests.py
2 files changed, 20 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index 928f68e..33b3e74 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -1030,19 +1030,23 @@
         self._params['token'] = tokens
         return True

-    def wait(self, delay: int | None = None) -> None:
+    def wait(self, delay: int | None = None, **kwargs) -> None:
         """Determine how long to wait after a failed request.

         Also reset last API error with wait cycles.

         .. version-added:: 9.0
+        .. version-changed:: 11.7
+           The *kwargs* parameter was added.

         :param delay: Minimum time in seconds to wait. Overwrites
             ``retry_wait`` variable if given. The delay doubles each
             retry until ``retry_max`` seconds is reached.
+        :param kwargs: Additional keyword arguments passed to
+            :meth:`WaitingMixin.wait`.
         """
         self.last_error = dict.fromkeys(['code', 'info'])
-        super().wait(delay)
+        super().wait(delay, **kwargs)

     def submit(self) -> dict:
         """Submit a query and parse the response.
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 86c90f6..d804e94 100755
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -70,6 +70,20 @@
         for item in req.items():
             self.assertLength(item, 2)

+    def test_wait_context(self) -> None:
+        """Test passing request context to the timeout exception."""
+        uri = 'https://yo.wikipedia.org/w/api.php'
+        req = api.Request(site=self.site, parameters={'action': 'query'},
+                          max_retries=0)
+        req.last_error = {'code': 'error', 'info': 'error'}
+
+        with self.assertRaises(pywikibot.exceptions.ApiTimeoutError) as cm:
+            req.wait(site=self.site, uri=uri)
+
+        self.assertIs(cm.exception.site, self.site)
+        self.assertEqual(cm.exception.uri, uri)
+        self.assertEqual(req.last_error, {'code': None, 'info': None})
+
     @suppress_warnings(
         'Instead of using kwargs |Both kwargs and parameters are set',
         DeprecationWarning)

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1326287?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia67f91047bf8c4b17d9c9279fd412fe4a5785454
Gerrit-Change-Number: 1326287
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to