[Bugs] #1561 UNSP: Most activities and Sugar itself chokes if the type of metadata returned is different from the expected one

Sugar Labs Bugs bugtracker-noreply at sugarlabs.org
Thu Nov 19 08:02:43 EST 2009


#1561: Most activities and Sugar itself chokes if the type of metadata returned is
different from the expected one
------------------------------------------+---------------------------------
    Reporter:  sayamindu                  |          Owner:  erikos                     
        Type:  defect                     |         Status:  new                        
    Priority:  Unspecified by Maintainer  |      Milestone:  Unspecified by Release Team
   Component:  sugar-toolkit              |        Version:  Git as of bugdate          
    Severity:  Unspecified                |       Keywords:  r?                         
Distribution:  Unspecified                |   Status_field:  Unconfirmed                
------------------------------------------+---------------------------------
 Consider the following in Journal code:
 {{{
 keep = int(self.metadata.get('keep', 0))
 }}}

 All is fine and well when the get() method returns an int. However, due to
 various factors (filesystem corruption, malformed journal bundles, etc),
 if the metadata type is something else, the code chokes.

 {{{
 1258525147.890608 ERROR root: Exception while displaying entry:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/site-packages/jarabe/journal/listview.py", line
 175, in _refresh_view
     entry.metadata = metadata_list[i]
   File "/usr/lib/python2.6/site-
 packages/jarabe/journal/collapsedentry.py", line 336, in set_metadata
     BaseCollapsedEntry.set_metadata(self, metadata)
   File "/usr/lib/python2.6/site-
 packages/jarabe/journal/collapsedentry.py", line 239, in set_metadata
     self.keep_icon.props.keep = self.get_keep()
   File "/usr/lib/python2.6/site-
 packages/jarabe/journal/collapsedentry.py", line 209, in get_keep
     keep = int(self.metadata.get('keep', 0))
 ValueError: invalid literal for int() with base 10: 'o'
 }}}

 A possible workaround is to use the following patch for the Journal code:

 {{{
 -        keep = int(self.metadata.get('keep', 0))
 +        try:
 +            keep = int(self.metadata.get('keep', 0))
 +        except ValueError:
 +            keep =  0
 }}}

 However, that would require patching of each and activity out there.
 A possible workaround would be to patch sugar-toolkit itself:

 {{{
 diff --git a/src/sugar/datastore/datastore.py
 b/src/sugar/datastore/datastore.py
 index 8d23721..10a4dda 100644
 --- a/src/sugar/datastore/datastore.py
 +++ b/src/sugar/datastore/datastore.py
 @@ -79,9 +79,16 @@ class DSMetadata(gobject.GObject):

      def get(self, key, default=None):
          if self._props.has_key(key):
 -            return self._props[key]
 -        else:
 -            return default
 +            retvalue = self._props[key]
 +            if default is None:
 +                return retvalue
 +            elif type(retvalue) == type(default):
 +                return retvalue
 +            else:
 +                logging.warning('The default metadata value \
 +                    type does not match the type in the datastore.')
 +
 +        return default
 }}}

 The patch assumes that the default value supplied would be correct, but I
 think we can safely consider that activity authors will supply the correct
 default value in most cases.

-- 
Ticket URL: <http://bugs.sugarlabs.org/ticket/1561>
Sugar Labs <http://sugarlabs.org/>
Sugar Labs bug tracking system


More information about the Bugs mailing list