Merge lp:~lifeless/python-oops-tools/bug-890001 into lp:python-oops-tools

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: 15
Merged at revision: 15
Proposed branch: lp:~lifeless/python-oops-tools/bug-890001
Merge into: lp:python-oops-tools
Diff against target: 83 lines (+54/-0)
3 files modified
src/oopstools/NEWS.txt (+3/-0)
src/oopstools/oops/models.py (+8/-0)
src/oopstools/oops/test/test_dboopsloader.py (+43/-0)
To merge this branch: bzr merge lp:~lifeless/python-oops-tools/bug-890001
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+82334@code.launchpad.net

Commit message

Handle a crash in oops-tools when a bad report has been generated by LP.

Description of the change

Handle a crash in oops-tools when a bad report has been generated by LP. This replaces a monkey patch we're currently running.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/oopstools/NEWS.txt'
--- src/oopstools/NEWS.txt 2011-11-11 04:00:56 +0000
+++ src/oopstools/NEWS.txt 2011-11-16 01:33:23 +0000
@@ -18,6 +18,9 @@
18* The req_vars variable in OOPS reports may now be a dict.18* The req_vars variable in OOPS reports may now be a dict.
19 (Robert Collins, #888866)19 (Robert Collins, #888866)
2020
21* Corrupt timeline objects are handled more gracefully if they are not a list,
22 or the list rows are too short or too long. (Robert Collins, #890001)
23
210.6.1240.6.1
22=====25=====
2326
2427
=== modified file 'src/oopstools/oops/models.py'
--- src/oopstools/oops/models.py 2011-11-11 04:00:56 +0000
+++ src/oopstools/oops/models.py 2011-11-16 01:33:23 +0000
@@ -345,6 +345,14 @@
345 elif key == 'HTTP_USER_AGENT':345 elif key == 'HTTP_USER_AGENT':
346 data['user_agent'] = conform(value, 200)346 data['user_agent'] = conform(value, 200)
347 statements = oops.get('timeline') or []347 statements = oops.get('timeline') or []
348 # Sanity check/coerce the statements into what we expect.
349 # Must be a list:
350 if not isinstance(statements, list):
351 statements = [(0, 0, 'badtimeline', str(statements))]
352 else:
353 filler = (0, 0, 'unknown', 'unknown')
354 for row, action in enumerate(statements):
355 statements[row] = tuple(action[:4]) + filler[len(action):]
348 duration = oops.get('duration')356 duration = oops.get('duration')
349 if duration is not None:357 if duration is not None:
350 total_time = int(duration * 1000)358 total_time = int(duration * 1000)
351359
=== modified file 'src/oopstools/oops/test/test_dboopsloader.py'
--- src/oopstools/oops/test/test_dboopsloader.py 2011-11-11 04:00:56 +0000
+++ src/oopstools/oops/test/test_dboopsloader.py 2011-11-16 01:33:23 +0000
@@ -186,3 +186,46 @@
186 }186 }
187 oops = parsed_oops_to_model_oops(report, 'bug-888866')187 oops = parsed_oops_to_model_oops(report, 'bug-888866')
188 self.assertEqual('myuseragent', oops.user_agent)188 self.assertEqual('myuseragent', oops.user_agent)
189
190 def test_nonlist_timeline(self):
191 # A timeline that is nonzero and not a list is turned into a one-entry
192 # timeline starting when the oops starts with no duration and category
193 # badtimeline.
194 report = {
195 'id': 'bug-890001-1',
196 'timeline': 'a'
197 }
198 oops = parsed_oops_to_model_oops(report, 'bug-890001-1')
199 self.assertEqual([(0, 0, 'badtimeline', 'a')], oops.statements)
200
201 def test_short_timeline_row(self):
202 # A timeline row that is short is padded with 'unknown' or 0's.
203 report = {
204 'id': 'bug-890001-2',
205 'timeline': [
206 (),
207 (1,),
208 (1, 2,),
209 (1, 2, 'foo'),
210 ],
211 }
212 oops = parsed_oops_to_model_oops(report, 'bug-890001-2')
213 self.assertEqual([
214 (0, 0, 'unknown', 'unknown'),
215 (1, 0, 'unknown', 'unknown'),
216 (1, 2, 'unknown', 'unknown'),
217 (1, 2, 'foo', 'unknown'),
218 ], oops.statements)
219
220 def test_long_timeline_row(self):
221 # A timeline row that is long is truncated.
222 report = {
223 'id': 'bug-890001-3',
224 'timeline': [
225 (1, 2, 'foo', 'bar', 'baz'),
226 ],
227 }
228 oops = parsed_oops_to_model_oops(report, 'bug-890001-3')
229 self.assertEqual([
230 (1, 2, 'foo', 'bar'),
231 ], oops.statements)

Subscribers

People subscribed via source and target branches

to all changes: