Skip to content

Commit 187d800

Browse files
authored
Fix AttributeError when client.get_default_node() returns None (#3458)
1 parent 601c1aa commit 187d800

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Diff for: redis/asyncio/cluster.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -1597,18 +1597,24 @@ async def _execute(
15971597
result.args = (msg,) + result.args[1:]
15981598
raise result
15991599

1600-
default_node = nodes.get(client.get_default_node().name)
1601-
if default_node is not None:
1602-
# This pipeline execution used the default node, check if we need
1603-
# to replace it.
1604-
# Note: when the error is raised we'll reset the default node in the
1605-
# caller function.
1606-
for cmd in default_node[1]:
1607-
# Check if it has a command that failed with a relevant
1608-
# exception
1609-
if type(cmd.result) in self.__class__.ERRORS_ALLOW_RETRY:
1610-
client.replace_default_node()
1611-
break
1600+
default_cluster_node = client.get_default_node()
1601+
1602+
# Check whether the default node was used. In some cases,
1603+
# 'client.get_default_node()' may return None. The check below
1604+
# prevents a potential AttributeError.
1605+
if default_cluster_node is not None:
1606+
default_node = nodes.get(default_cluster_node.name)
1607+
if default_node is not None:
1608+
# This pipeline execution used the default node, check if we need
1609+
# to replace it.
1610+
# Note: when the error is raised we'll reset the default node in the
1611+
# caller function.
1612+
for cmd in default_node[1]:
1613+
# Check if it has a command that failed with a relevant
1614+
# exception
1615+
if type(cmd.result) in self.__class__.ERRORS_ALLOW_RETRY:
1616+
client.replace_default_node()
1617+
break
16121618

16131619
return [cmd.result for cmd in stack]
16141620

0 commit comments

Comments
 (0)