SQLAlchemy Query.all() can't raise NoResultFound exception

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

Bug Description

all() returns an empty list when no result is found, so there is no sense to except NoResultFound and return an empty list like the following code does:

        try:
            dns_qry = context.session.query(models_v2.DNSNameServer)
            return dns_qry.filter_by(subnet_id=subnet_id).all()
        except exc.NoResultFound:
            return []

We have a lot of such cases in our code which should be fixed.

Tags: db
tags: added: db
Changed in quantum:
assignee: nobody → Roman Podolyaka (rpodolyaka)
Changed in quantum:
status: New → Confirmed
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/27687

Changed in quantum:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to quantum (master)

Reviewed: https://review.openstack.org/27687
Committed: http://github.com/openstack/quantum/commit/daaf2b6d6502da4f185ed65a21a75ab2aab2d1b7
Submitter: Jenkins
Branch: master

commit daaf2b6d6502da4f185ed65a21a75ab2aab2d1b7
Author: Roman Podolyaka <email address hidden>
Date: Fri Apr 26 18:27:39 2013 +0300

    Fix usage of Query.all() and NoResultFound

    SQLAlchemy Query.all() method doesn't raise NoResultFound
    exception in case if no result is found but rather returns
    an empty list. So this pattern which is common for our code
    doesn't make sense and should be fixed:

        try:
            dns_qry = context.session.query(models_v2.DNSNameServer)
            return dns_qry.filter_by(subnet_id=subnet_id).all()
        except exc.NoResultFound:
            return []

    Fixes bug 1173131.

    Change-Id: I19b64eecd6edac0dba7dd0bf2ab32690c46e4f8b

Changed in quantum:
status: In Progress → Fix Committed
Changed in quantum:
milestone: none → havana-1
importance: Undecided → Low
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.