← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/python-oops-tools/fix-str-coerce-list into lp:python-oops-tools

 

William Grant has proposed merging lp:~wgrant/python-oops-tools/fix-str-coerce-list into lp:python-oops-tools.

Commit message:
Fix statement string coercion to cope with non-tuple actions.

Requested reviews:
  python-oops-tools reviewers (oops-tools-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/python-oops-tools/fix-str-coerce-list/+merge/313339

Fix statement string coercion to cope with non-tuple actions.

We tend to encode actions as lists, not tuples, which causes the
coercion to fail when it tries to concatenate a list and a tuple.

This hit SSO when it started sending statements as binary rather than
string.

-- 
Your team python-oops-tools reviewers is requested to review the proposed merge of lp:~wgrant/python-oops-tools/fix-str-coerce-list into lp:python-oops-tools.
=== modified file 'src/oopstools/oops/models.py'
--- src/oopstools/oops/models.py	2013-02-25 21:41:12 +0000
+++ src/oopstools/oops/models.py	2016-12-15 10:20:18 +0000
@@ -387,11 +387,14 @@
     else:
         filler = (0, 0, 'unknown', 'unknown', 'unknown')
         for row, action in enumerate(statements):
+            # action is expected to be a tuple, but most formats encode it as a
+            # list.
+            action = tuple(action)
             # Must have a string as the statement
             if len(action) > 3 and not isinstance(action[3], basestring):
                 action = action[:3] + (str(action[3]),) + action[4:]
             # Must have length == 5
-            statements[row] = tuple(action[:5]) + filler[len(action):]
+            statements[row] = action[:5] + filler[len(action):]
     duration = oops.get('duration')
     if duration is not None:
         total_time = int(duration * 1000)

=== modified file 'src/oopstools/oops/test/test_dboopsloader.py'
--- src/oopstools/oops/test/test_dboopsloader.py	2013-02-25 21:41:12 +0000
+++ src/oopstools/oops/test/test_dboopsloader.py	2016-12-15 10:20:18 +0000
@@ -238,7 +238,7 @@
         report = {
             'id': 'dict-statement',
             'timeline': [
-                (1, 2, 'foo', {}, 'baz'),
+                [1, 2, 'foo', {}, 'baz'],
                 ],
         }
         oops = parsed_oops_to_model_oops(report, 'dict-statement')