← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1267074] Re: type() method should be replaced with isinstance() in stone/__init__.py

 

** Changed in: glance
       Status: Fix Committed => Fix Released

** Changed in: glance
    Milestone: None => icehouse-2

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/1267074

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

Status in OpenStack Image Registry and Delivery Service (Glance):
  Fix Released

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)

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/1267074/+subscriptions


References