Skip to content

Commit

Permalink
add guard to qualified_replica
Browse files Browse the repository at this point in the history
fixes 'NoneType' object is not subscriptable
if there is no share instance, probably because it has been
deleted in the meantime

Change-Id: I3e0b7d02337255497c4d18a7d41d5c5bc269a1cd
  • Loading branch information
Carthaca committed Apr 22, 2021
1 parent 94f3350 commit 0b78f96
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions manila/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,11 @@ def instance(self):
result = None
if len(self.instances) > 0:
def qualified_replica(x):
preferred_statuses = (constants.REPLICA_STATE_ACTIVE,)
return x['replica_state'] in preferred_statuses
if x is None:
return False
else:
preferred_statuses = (constants.REPLICA_STATE_ACTIVE,)
return x['replica_state'] in preferred_statuses

replica_snapshots = list(filter(
lambda x: qualified_replica(x.share_instance), self.instances))
Expand Down Expand Up @@ -714,9 +717,12 @@ def aggregate_status(self):
"""

def qualified_replica(x):
preferred_statuses = (constants.REPLICA_STATE_ACTIVE,
constants.REPLICA_STATE_IN_SYNC)
return x['replica_state'] in preferred_statuses
if x is None:
return False
else:
preferred_statuses = (constants.REPLICA_STATE_ACTIVE,
constants.REPLICA_STATE_IN_SYNC)
return x['replica_state'] in preferred_statuses

replica_snapshots = list(filter(
lambda x: qualified_replica(x['share_instance']), self.instances))
Expand Down

0 comments on commit 0b78f96

Please sign in to comment.