Merge lp:~rye/python-oops-tools/trim-url-lp915335 into lp:python-oops-tools

Proposed by Roman Yepishev
Status: Merged
Approved by: Robert Collins
Approved revision: 35
Merged at revision: 36
Proposed branch: lp:~rye/python-oops-tools/trim-url-lp915335
Merge into: lp:python-oops-tools
Diff against target: 51 lines (+18/-1)
2 files modified
src/oopstools/oops/models.py (+2/-1)
src/oopstools/oops/test/test_dboopsloader.py (+16/-0)
To merge this branch: bzr merge lp:~rye/python-oops-tools/trim-url-lp915335
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+116659@code.launchpad.net

Commit message

Trim URL after all the quoting

Description of the change

This fixes the issue when a broken URL expands to more than 500 (MAX_URL_LEN) when quoted and makes the database unhappy.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

cool

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 2011-12-08 04:57:25 +0000
+++ src/oopstools/oops/models.py 2012-07-25 14:28:57 +0000
@@ -433,7 +433,7 @@
433 # Trim most_expensive_statements to 200 characters433 # Trim most_expensive_statements to 200 characters
434 if most_expensive_statement is not None:434 if most_expensive_statement is not None:
435 most_expensive_statement = conform(most_expensive_statement, 200)435 most_expensive_statement = conform(most_expensive_statement, 200)
436 url = conform(oops.get('url') or '', MAX_URL_LEN)436 url = oops.get('url') or ''
437 if type(url) is unicode:437 if type(url) is unicode:
438 # We have gotten a ringer, URL's are bytestrings. Encode to UTF8 to get438 # We have gotten a ringer, URL's are bytestrings. Encode to UTF8 to get
439 # a bytestring and urllib.quote to get a url.439 # a bytestring and urllib.quote to get a url.
@@ -447,6 +447,7 @@
447 # to quote it to make it a valid URL - this is better than447 # to quote it to make it a valid URL - this is better than
448 # rejecting the OOPS, or having a URL that isn't in the DB.448 # rejecting the OOPS, or having a URL that isn't in the DB.
449 url = urllib.quote(url)449 url = urllib.quote(url)
450 url = conform(url, MAX_URL_LEN)
450451
451 informational = oops.get('informational', 'False').lower() == 'true'452 informational = oops.get('informational', 'False').lower() == 'true'
452 oops_date = oops.get('time')453 oops_date = oops.get('time')
453454
=== modified file 'src/oopstools/oops/test/test_dboopsloader.py'
--- src/oopstools/oops/test/test_dboopsloader.py 2011-11-17 16:11:12 +0000
+++ src/oopstools/oops/test/test_dboopsloader.py 2012-07-25 14:28:57 +0000
@@ -36,6 +36,7 @@
36 DBOopsRootDirectory,36 DBOopsRootDirectory,
37 Oops,37 Oops,
38 parsed_oops_to_model_oops,38 parsed_oops_to_model_oops,
39 MAX_URL_LEN
39 )40 )
4041
4142
@@ -253,3 +254,18 @@
253 }254 }
254 oops = parsed_oops_to_model_oops(report, 'bug-891647')255 oops = parsed_oops_to_model_oops(report, 'bug-891647')
255 self.assertEqual('APPSERVER', oops.appinstance.title)256 self.assertEqual('APPSERVER', oops.appinstance.title)
257
258 def test_long_url_bug_915335(self):
259 # URLs that are longer than 500 characters should be truncated
260 # at all times.
261 url = 'http://' + '\xFF' * 250
262
263 report = {
264 'id': 'OOPS-68383510f5054932567230492013ce91',
265 'url': url
266 }
267
268 oops = parsed_oops_to_model_oops(report, 'bug-915335')
269 oops.save()
270 self.assertTrue(len(oops.url) < MAX_URL_LEN)
271

Subscribers

People subscribed via source and target branches

to all changes: