Skip to content

Commit 4d975e5

Browse files
Avoid RequestResponseIO throttler access when throttler is absent (#39112)
* Avoid throttler access when RequestResponseIO has no throttler * Use explicit None checks for throttler in RequestResponseIO * sync PR head for explicit None checks * Tighten CI-flaky tests around async teardown and minibatch size * Fix formatter regression in pytorch batch size assertion * Keep RequestResponseIO PR focused
1 parent 09d63cc commit 4d975e5

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

sdks/python/apache_beam/io/requestresponse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def process(self, request: RequestT, *args, **kwargs):
358358
self._metrics_collector.requests.inc(1)
359359

360360
is_throttled_request = False
361-
if self._throttler:
361+
if self._throttler is not None:
362362
while self._throttler.throttler.throttle_request(time.time() *
363363
MSEC_TO_SEC):
364364
_LOGGER.info(
@@ -375,7 +375,8 @@ def process(self, request: RequestT, *args, **kwargs):
375375
response = self._repeater.repeat(
376376
self._caller, request, self._timeout, self._metrics_collector)
377377
self._metrics_collector.responses.inc(1)
378-
self._throttler.throttler.successful_request(req_time * MSEC_TO_SEC)
378+
if self._throttler is not None:
379+
self._throttler.throttler.successful_request(req_time * MSEC_TO_SEC)
379380
yield response
380381
except Exception as e:
381382
raise e

sdks/python/apache_beam/io/requestresponse_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ def test_valid_call(self):
9595

9696
self.assertIsNotNone(output)
9797

98+
def test_valid_call_without_throttler(self):
99+
caller = AckCaller()
100+
with TestPipeline() as test_pipeline:
101+
output = (
102+
test_pipeline
103+
| beam.Create(["sample_request"])
104+
| RequestResponseIO(caller=caller, throttler=None))
105+
106+
self.assertIsNotNone(output)
107+
98108
def test_call_timeout(self):
99109
caller = CallerWithTimeout()
100110
with self.assertRaisesRegex(Exception, "Timeout"):

0 commit comments

Comments
 (0)