@@ -956,6 +956,11 @@ def _request(
956
956
stream : bool ,
957
957
stream_cls : type [_StreamT ] | None ,
958
958
) -> ResponseT | _StreamT :
959
+ # create a copy of the options we were given so that if the
960
+ # options are mutated later & we then retry, the retries are
961
+ # given the original options
962
+ input_options = model_copy (options )
963
+
959
964
cast_to = self ._maybe_override_cast_to (cast_to , options )
960
965
self ._prepare_options (options )
961
966
@@ -980,7 +985,7 @@ def _request(
980
985
981
986
if retries > 0 :
982
987
return self ._retry_request (
983
- options ,
988
+ input_options ,
984
989
cast_to ,
985
990
retries ,
986
991
stream = stream ,
@@ -995,7 +1000,7 @@ def _request(
995
1000
996
1001
if retries > 0 :
997
1002
return self ._retry_request (
998
- options ,
1003
+ input_options ,
999
1004
cast_to ,
1000
1005
retries ,
1001
1006
stream = stream ,
@@ -1023,7 +1028,7 @@ def _request(
1023
1028
if retries > 0 and self ._should_retry (err .response ):
1024
1029
err .response .close ()
1025
1030
return self ._retry_request (
1026
- options ,
1031
+ input_options ,
1027
1032
cast_to ,
1028
1033
retries ,
1029
1034
err .response .headers ,
@@ -1532,6 +1537,11 @@ async def _request(
1532
1537
# execute it earlier while we are in an async context
1533
1538
self ._platform = await asyncify (get_platform )()
1534
1539
1540
+ # create a copy of the options we were given so that if the
1541
+ # options are mutated later & we then retry, the retries are
1542
+ # given the original options
1543
+ input_options = model_copy (options )
1544
+
1535
1545
cast_to = self ._maybe_override_cast_to (cast_to , options )
1536
1546
await self ._prepare_options (options )
1537
1547
@@ -1554,7 +1564,7 @@ async def _request(
1554
1564
1555
1565
if retries > 0 :
1556
1566
return await self ._retry_request (
1557
- options ,
1567
+ input_options ,
1558
1568
cast_to ,
1559
1569
retries ,
1560
1570
stream = stream ,
@@ -1569,7 +1579,7 @@ async def _request(
1569
1579
1570
1580
if retries > 0 :
1571
1581
return await self ._retry_request (
1572
- options ,
1582
+ input_options ,
1573
1583
cast_to ,
1574
1584
retries ,
1575
1585
stream = stream ,
@@ -1592,7 +1602,7 @@ async def _request(
1592
1602
if retries > 0 and self ._should_retry (err .response ):
1593
1603
await err .response .aclose ()
1594
1604
return await self ._retry_request (
1595
- options ,
1605
+ input_options ,
1596
1606
cast_to ,
1597
1607
retries ,
1598
1608
err .response .headers ,
0 commit comments