type() method should be replaced with isinstance() in stone/__init__.py

Bug #1267074 reported by wanghong
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Wishlist
wanghong

Bug Description

In store/__init__.py, there is two places use the "type" method to determine the type. It's bertter to use the "isinstance" method instead.

The code is:

def check_location_metadata(val, key=''):
    t = type(val)
    if t == dict:
        for key in val:
            check_location_metadata(val[key], key=key)
    elif t == list:
        ndx = 0
        for v in val:
            check_location_metadata(v, key='%s[%d]' % (key, ndx))
            ndx = ndx + 1
    elif t != unicode:
        raise BackendException(_("The image metadata key %s has an invalid "
                                 "type of %s. Only dict, list, and unicode "
                                 "are supported.") % (key, str(t)))

def store_add_to_backend(image_id, data, size, store):
    (location, size, checksum, metadata) = store.add(image_id, data, size)
    if metadata is not None:
        if type(metadata) != dict:
            msg = (_("The storage driver %s returned invalid metadata %s"
                     "This must be a dictionary type") %
                   (str(store), str(metadata)))
            LOG.error(msg)
            raise BackendException(msg)

wanghong (w-wanghong)
Changed in glance:
assignee: nobody → wanghong (w-wanghong)
Feilong Wang (flwang)
Changed in glance:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

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

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

Reviewed: https://review.openstack.org/65611
Committed: https://git.openstack.org/cgit/openstack/glance/commit/?id=ff1f6607e71ee261a9499b4a11de34e3648c570b
Submitter: Jenkins
Branch: master

commit ff1f6607e71ee261a9499b4a11de34e3648c570b
Author: wanghong <email address hidden>
Date: Thu Jan 9 11:49:56 2014 +0800

    replace type calls with isinstance

    In store/__init__.py, there are two uses of the "type" method to
    check type compatibility. It is better to use the "isinstance" method
    since it will work for subtypes as well.

    Change-Id: I20958aa449822cac2cb03e12557fded3f45a9e05
    Closes-Bug: #1267074

Changed in glance:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
milestone: none → icehouse-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in glance:
milestone: icehouse-2 → 2014.1
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.