Skip to content

Commit 2091636

Browse files
committed
Fix AttributeError when client.get_default_node() returns None
1 parent 8f2276e commit 2091636

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

redis/asyncio/cluster.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -1568,18 +1568,22 @@ async def _execute(
15681568
result.args = (msg,) + result.args[1:]
15691569
raise result
15701570

1571-
default_node = nodes.get(client.get_default_node().name)
1572-
if default_node is not None:
1573-
# This pipeline execution used the default node, check if we need
1574-
# to replace it.
1575-
# Note: when the error is raised we'll reset the default node in the
1576-
# caller function.
1577-
for cmd in default_node[1]:
1578-
# Check if it has a command that failed with a relevant
1579-
# exception
1580-
if type(cmd.result) in self.__class__.ERRORS_ALLOW_RETRY:
1581-
client.replace_default_node()
1582-
break
1571+
default_cluster_node = client.get_default_node()
1572+
if default_cluster_node is not None:
1573+
# Not sure why default_cluster_node is sometimes None; maybe if the object is being
1574+
# closed during an execution? Either way, this avoids a potential AttributeError
1575+
default_node = nodes.get(default_cluster_node.name)
1576+
if default_node is not None:
1577+
# This pipeline execution used the default node, check if we need
1578+
# to replace it.
1579+
# Note: when the error is raised we'll reset the default node in the
1580+
# caller function.
1581+
for cmd in default_node[1]:
1582+
# Check if it has a command that failed with a relevant
1583+
# exception
1584+
if type(cmd.result) in self.__class__.ERRORS_ALLOW_RETRY:
1585+
client.replace_default_node()
1586+
break
15831587

15841588
return [cmd.result for cmd in stack]
15851589

0 commit comments

Comments
 (0)