diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 7c589046990..ded5a323d29 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -614,8 +614,13 @@ def delete_security_group_rule(self, context, id): raise ext_sg.SecurityGroupRuleInUse(id=id, reason=reason) with context.session.begin(subtransactions=True): - query = self._model_query(context, SecurityGroupRule) - if query.filter(SecurityGroupRule.id == id).delete() == 0: + query = self._model_query(context, SecurityGroupRule).filter( + SecurityGroupRule.id == id) + try: + # As there is a filter on a primary key it is not possible for + # MultipleResultsFound to be raised + context.session.delete(query.one()) + except exc.NoResultFound: raise ext_sg.SecurityGroupRuleNotFound(id=id) registry.notify(