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

Proposed by William Grant
Status: Merged
Approved by: William Grant
Approved revision: 56
Merged at revision: 56
Proposed branch: lp:~wgrant/python-oops-tools/fix-str-coerce-list
Merge into: lp:python-oops-tools
Diff against target: 32 lines (+5/-2)
2 files modified
src/oopstools/oops/models.py (+4/-1)
src/oopstools/oops/test/test_dboopsloader.py (+1/-1)
To merge this branch: bzr merge lp:~wgrant/python-oops-tools/fix-str-coerce-list
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+313339@code.launchpad.net

Commit message

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

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
387 else:387 else:
388 filler = (0, 0, 'unknown', 'unknown', 'unknown')388 filler = (0, 0, 'unknown', 'unknown', 'unknown')
389 for row, action in enumerate(statements):389 for row, action in enumerate(statements):
390 # action is expected to be a tuple, but most formats encode it as a
391 # list.
392 action = tuple(action)
390 # Must have a string as the statement393 # Must have a string as the statement
391 if len(action) > 3 and not isinstance(action[3], basestring):394 if len(action) > 3 and not isinstance(action[3], basestring):
392 action = action[:3] + (str(action[3]),) + action[4:]395 action = action[:3] + (str(action[3]),) + action[4:]
393 # Must have length == 5396 # Must have length == 5
394 statements[row] = tuple(action[:5]) + filler[len(action):]397 statements[row] = action[:5] + filler[len(action):]
395 duration = oops.get('duration')398 duration = oops.get('duration')
396 if duration is not None:399 if duration is not None:
397 total_time = int(duration * 1000)400 total_time = int(duration * 1000)
398401
=== 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 @@
238 report = {238 report = {
239 'id': 'dict-statement',239 'id': 'dict-statement',
240 'timeline': [240 'timeline': [
241 (1, 2, 'foo', {}, 'baz'),241 [1, 2, 'foo', {}, 'baz'],
242 ],242 ],
243 }243 }
244 oops = parsed_oops_to_model_oops(report, 'dict-statement')244 oops = parsed_oops_to_model_oops(report, 'dict-statement')

Subscribers

People subscribed via source and target branches

to all changes: