@@ -955,6 +955,11 @@ def _request(
955
955
stream : bool ,
956
956
stream_cls : type [_StreamT ] | None ,
957
957
) -> ResponseT | _StreamT :
958
+ # create a copy of the options we were given so that if the
959
+ # options are mutated later & we then retry, the retries are
960
+ # given the original options
961
+ input_options = model_copy (options )
962
+
958
963
cast_to = self ._maybe_override_cast_to (cast_to , options )
959
964
self ._prepare_options (options )
960
965
@@ -979,7 +984,7 @@ def _request(
979
984
980
985
if retries > 0 :
981
986
return self ._retry_request (
982
- options ,
987
+ input_options ,
983
988
cast_to ,
984
989
retries ,
985
990
stream = stream ,
@@ -994,7 +999,7 @@ def _request(
994
999
995
1000
if retries > 0 :
996
1001
return self ._retry_request (
997
- options ,
1002
+ input_options ,
998
1003
cast_to ,
999
1004
retries ,
1000
1005
stream = stream ,
@@ -1022,7 +1027,7 @@ def _request(
1022
1027
if retries > 0 and self ._should_retry (err .response ):
1023
1028
err .response .close ()
1024
1029
return self ._retry_request (
1025
- options ,
1030
+ input_options ,
1026
1031
cast_to ,
1027
1032
retries ,
1028
1033
err .response .headers ,
@@ -1518,6 +1523,11 @@ async def _request(
1518
1523
# execute it earlier while we are in an async context
1519
1524
self ._platform = await asyncify (get_platform )()
1520
1525
1526
+ # create a copy of the options we were given so that if the
1527
+ # options are mutated later & we then retry, the retries are
1528
+ # given the original options
1529
+ input_options = model_copy (options )
1530
+
1521
1531
cast_to = self ._maybe_override_cast_to (cast_to , options )
1522
1532
await self ._prepare_options (options )
1523
1533
@@ -1540,7 +1550,7 @@ async def _request(
1540
1550
1541
1551
if retries > 0 :
1542
1552
return await self ._retry_request (
1543
- options ,
1553
+ input_options ,
1544
1554
cast_to ,
1545
1555
retries ,
1546
1556
stream = stream ,
@@ -1555,7 +1565,7 @@ async def _request(
1555
1565
1556
1566
if retries > 0 :
1557
1567
return await self ._retry_request (
1558
- options ,
1568
+ input_options ,
1559
1569
cast_to ,
1560
1570
retries ,
1561
1571
stream = stream ,
@@ -1578,7 +1588,7 @@ async def _request(
1578
1588
if retries > 0 and self ._should_retry (err .response ):
1579
1589
await err .response .aclose ()
1580
1590
return await self ._retry_request (
1581
- options ,
1591
+ input_options ,
1582
1592
cast_to ,
1583
1593
retries ,
1584
1594
err .response .headers ,
0 commit comments