@@ -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 ,
@@ -1024,7 +1029,7 @@ def _request(
1024
1029
if retries > 0 and self ._should_retry (err .response ):
1025
1030
err .response .close ()
1026
1031
return self ._retry_request (
1027
- options ,
1032
+ input_options ,
1028
1033
cast_to ,
1029
1034
retries ,
1030
1035
err .response .headers ,
@@ -1533,6 +1538,11 @@ async def _request(
1533
1538
# execute it earlier while we are in an async context
1534
1539
self ._platform = await asyncify (get_platform )()
1535
1540
1541
+ # create a copy of the options we were given so that if the
1542
+ # options are mutated later & we then retry, the retries are
1543
+ # given the original options
1544
+ input_options = model_copy (options )
1545
+
1536
1546
cast_to = self ._maybe_override_cast_to (cast_to , options )
1537
1547
await self ._prepare_options (options )
1538
1548
@@ -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 ,
@@ -1570,7 +1580,7 @@ async def _request(
1570
1580
1571
1581
if retries > 0 :
1572
1582
return await self ._retry_request (
1573
- options ,
1583
+ input_options ,
1574
1584
cast_to ,
1575
1585
retries ,
1576
1586
stream = stream ,
@@ -1593,7 +1603,7 @@ async def _request(
1593
1603
if retries > 0 and self ._should_retry (err .response ):
1594
1604
await err .response .aclose ()
1595
1605
return await self ._retry_request (
1596
- options ,
1606
+ input_options ,
1597
1607
cast_to ,
1598
1608
retries ,
1599
1609
err .response .headers ,
0 commit comments