@@ -317,10 +317,38 @@ def mock_iter_content(chunk_size):
317317 assert all (len (c ) <= chunk_size for c in content_chunks ) # chunks don't exceed size
318318
319319
320+ def test_no_retry_on_non_seekable_stream ():
321+ requests = []
322+
323+ # Always respond with a response that triggers a retry.
324+ def inner (h : BaseHTTPRequestHandler ):
325+ content_length = int (h .headers .get ('Content-Length' , 0 ))
326+ if content_length > 0 :
327+ requests .append (h .rfile .read (content_length ))
328+
329+ h .send_response (429 )
330+ h .send_header ('Retry-After' , '1' )
331+ h .end_headers ()
332+
333+ stream = io .BytesIO (b"test data" )
334+ stream .seekable = lambda : False # makes the stream appear non-seekable
335+
336+ with http_fixture_server (inner ) as host :
337+ client = _BaseClient ()
338+
339+ # Should raise error immediately without retry.
340+ with pytest .raises (DatabricksError ):
341+ client .do ('POST' , f'{ host } /foo' , data = stream )
342+
343+ # Verify that only one request was made (no retries).
344+ assert len (requests ) == 1
345+ assert requests [0 ] == b"test data"
346+
347+
320348def test_perform_resets_seekable_stream_on_error ():
321349 received_data = []
322350
323- # Response that triggers a retry.
351+ # Always respond with a response that triggers a retry.
324352 def inner (h : BaseHTTPRequestHandler ):
325353 content_length = int (h .headers .get ('Content-Length' , 0 ))
326354 if content_length > 0 :
@@ -340,7 +368,7 @@ def inner(h: BaseHTTPRequestHandler):
340368 stream .read (4 )
341369 assert stream .tell () == 4
342370
343- # Call perform which should fail but reset the stream.
371+ # Should fail but reset the stream.
344372 with pytest .raises (DatabricksError ):
345373 client ._perform ('POST' , f'{ host } /foo' , data = stream )
346374
@@ -353,7 +381,7 @@ def inner(h: BaseHTTPRequestHandler):
353381def test_perform_does_not_reset_nonseekable_stream_on_error ():
354382 received_data = []
355383
356- # Response that triggers a retry.
384+ # Always respond with a response that triggers a retry.
357385 def inner (h : BaseHTTPRequestHandler ):
358386 content_length = int (h .headers .get ('Content-Length' , 0 ))
359387 if content_length > 0 :
@@ -374,7 +402,7 @@ def inner(h: BaseHTTPRequestHandler):
374402 stream .read (4 )
375403 assert stream .tell () == 4
376404
377- # Call perform which should fail but reset the stream.
405+ # Should fail without resetting the stream.
378406 with pytest .raises (DatabricksError ):
379407 client ._perform ('POST' , f'{ host } /foo' , data = stream )
380408
0 commit comments