]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix usage of SQLAlchemy Query.first() method
authorRoman Podolyaka <rpodolyaka@mirantis.com>
Wed, 8 May 2013 15:34:51 +0000 (18:34 +0300)
committerRoman Podolyaka <rpodolyaka@mirantis.com>
Wed, 8 May 2013 19:30:08 +0000 (22:30 +0300)
Query.first() doesn't raise the NoResultFound exception
if no result is found but rather returns None, so wrapping
of Query.first() call into a try/except NoResultFound block
is useless.

Fixes bug 1177842.

Change-Id: I0bd0e6d8299734b485dd1a1ac36bf6c295fd8932

quantum/plugins/nicira/nicira_qos_db.py

index a251a3fe2249f90a86c09c039a67e0f719e37619..f719db4a5ef3189195cafeb1bd0295f40fe985a3 100644 (file)
@@ -132,16 +132,10 @@ class NVPQoSDbMixin(ext_qos.QueuePluginBase):
 
     def _delete_network_queue_mapping(self, context, network_id):
         query = self._model_query(context, NetworkQueueMapping)
-        try:
-            with context.session.begin(subtransactions=True):
-                binding = query.filter_by(network_id=network_id).first()
-                if binding:
-                    context.session.delete(binding)
-        except exc.NoResultFound:
-            # return since this can happen if we are updating a port that
-            # did not already have a queue on it. There is no need to check
-            # if there is one before deleting if we return here.
-            return
+        with context.session.begin(subtransactions=True):
+            binding = query.filter_by(network_id=network_id).first()
+            if binding:
+                context.session.delete(binding)
 
     def _extend_port_qos_queue(self, context, port):
         if self._check_view_auth(context, {'qos_queue': None},