@@ -1515,7 +1515,7 @@ async def _execute(
1515
1515
allow_redirections : bool = True ,
1516
1516
) -> List [Any ]:
1517
1517
todo = [
1518
- cmd for cmd in stack if not cmd .result or isinstance ( cmd .result , Exception )
1518
+ cmd for cmd in stack if not cmd .unwrap_result () or cmd .get_all_exceptions ( )
1519
1519
]
1520
1520
1521
1521
nodes = {}
@@ -1548,18 +1548,22 @@ async def _execute(
1548
1548
if allow_redirections :
1549
1549
# send each errored command individually
1550
1550
for cmd in todo :
1551
- if isinstance (cmd .result , (TryAgainError , MovedError , AskError )):
1552
- try :
1553
- result = await client .execute_command (
1554
- * cmd .args , ** cmd .kwargs
1555
- )
1556
- except Exception as e :
1557
- result = e
1551
+ for name , exc in cmd .get_all_exceptions ():
1552
+ if isinstance (exc , (TryAgainError , MovedError , AskError )):
1553
+ try :
1554
+ result = await client .execute_command (
1555
+ * cmd .args , ** cmd .kwargs
1556
+ )
1557
+ except Exception as e :
1558
+ result = e
1558
1559
1559
- if isinstance (result , dict ):
1560
- cmd .result = result
1561
- else :
1562
- cmd .set_node_result (cmd .target_nodes [0 ].name , result )
1560
+ if isinstance (result , dict ):
1561
+ cmd .result = result
1562
+ else :
1563
+ cmd .set_node_result (name , result )
1564
+
1565
+ # We have already retried the command on all nodes.
1566
+ break
1563
1567
1564
1568
if raise_on_error :
1565
1569
for cmd in todo :
@@ -1583,11 +1587,16 @@ async def _execute(
1583
1587
# to replace it.
1584
1588
# Note: when the error is raised we'll reset the default node in the
1585
1589
# caller function.
1590
+ has_exc = False
1586
1591
for cmd in default_node [1 ]:
1587
1592
# Check if it has a command that failed with a relevant
1588
1593
# exception
1589
- if type (cmd .result ) in self .__class__ .ERRORS_ALLOW_RETRY :
1590
- client .replace_default_node ()
1594
+ for name , exc in cmd .get_all_exceptions ():
1595
+ if type (exc ) in self .__class__ .ERRORS_ALLOW_RETRY :
1596
+ client .replace_default_node ()
1597
+ has_exc = True
1598
+ break
1599
+ if has_exc :
1591
1600
break
1592
1601
1593
1602
return [cmd .unwrap_result () for cmd in stack ]
@@ -1649,5 +1658,8 @@ def get_first_exception(self) -> Optional[Tuple[str, Exception]]:
1649
1658
((n , r ) for n , r in self .result .items () if isinstance (r , Exception )), None
1650
1659
)
1651
1660
1661
+ def get_all_exceptions (self ) -> List [Tuple [str , Exception ]]:
1662
+ return [(n , r ) for n , r in self .result .items () if isinstance (r , Exception )]
1663
+
1652
1664
def __repr__ (self ) -> str :
1653
1665
return f"[{ self .position } ] { self .args } ({ self .kwargs } )"
0 commit comments