SQLAlchemy Query.first() can't raise the NoResultFound exception

Bug #1177842 reported by Roman Podoliaka
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Roman Podoliaka

Bug Description

SQLAlchemy Query.first() is used incorrectly in this code fragment of quantum/plugins/nicira/nicira_qos_db.py:

       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

In fact, Query.first() doesn't raise the NoResultFound exception if no result is found but rather returns None.

Tags: db nicira
Changed in quantum:
assignee: nobody → Roman Podolyaka (rpodolyaka)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to quantum (master)

Fix proposed to branch: master
Review: https://review.openstack.org/28571

Changed in quantum:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to quantum (master)

Reviewed: https://review.openstack.org/28571
Committed: http://github.com/openstack/quantum/commit/6d26dd57680ddcdfc3c31fbe2d7190e0f6d28d0d
Submitter: Jenkins
Branch: master

commit 6d26dd57680ddcdfc3c31fbe2d7190e0f6d28d0d
Author: Roman Podolyaka <email address hidden>
Date: Wed May 8 18:34:51 2013 +0300

    Fix usage of SQLAlchemy Query.first() method

    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

Changed in quantum:
status: In Progress → Fix Committed
Changed in quantum:
milestone: none → havana-1
Thierry Carrez (ttx)
Changed in quantum:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in neutron:
milestone: havana-1 → 2013.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.