Merge lp:~brian-murray/errors/bucket-unicode-oops into lp:errors

Proposed by Brian Murray
Status: Merged
Approved by: Evan
Approved revision: 433
Merged at revision: 434
Proposed branch: lp:~brian-murray/errors/bucket-unicode-oops
Merge into: lp:errors
Diff against target: 22 lines (+4/-1)
1 file modified
errors/api/resources.py (+4/-1)
To merge this branch: bzr merge lp:~brian-murray/errors/bucket-unicode-oops
Reviewer Review Type Date Requested Status
Evan (community) Approve
Review via email: mp+168810@code.launchpad.net

Commit message

Fix some unicode errors in the phased update regression detection code.

Description of the change

I was getting the following oops when testing the phased update regression detection code:

  File "/usr/lib/pymodules/python2.7/tastypie/resources.py", line 196, in wrapper
    response = callback(request, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/tastypie/resources.py", line 421, in dispatch_list
    return self.dispatch('list', request, **kwargs)
  File "/var/www/errors/errors/metrics.py", line 40, in wrapper
    result = view(*args, **kwargs)
  File "/var/www/errors/errors/api/resources.py", line 74, in dispatch
    return Resource.dispatch(self, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/tastypie/resources.py", line 454, in dispatch
    response = method(request, **kwargs)
  File "/usr/lib/pymodules/python2.7/tastypie/resources.py", line 1115, in get_list
    to_be_serialized['objects'] = [self.full_dehydrate(bundle) for bundle in bundles]
  File "/usr/lib/pymodules/python2.7/tastypie/resources.py", line 719, in full_dehydrate
    bundle.data[field_name] = field_object.dehydrate(bundle)
  File "/usr/lib/pymodules/python2.7/tastypie/fields.py", line 121, in dehydrate
    return self.convert(current_object)
  File "/usr/lib/pymodules/python2.7/tastypie/fields.py", line 182, in convert
    return unicode(value)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 77: ordinal not in range(128)

This fixes that. A simple test is passing a unicode bucket to sha1:

In [1]: from hashlib import sha1

In [2]: sha1(u"/usr/bin/nm-applet:nm-applet: ../../src/xcb_io.c:528: _XAllocID: La declaraci\xf3n `ret != inval_id' no se cumple.")
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-2-5dbb7ef925f4> in <module>()
----> 1 sha1(u"/usr/bin/nm-applet:nm-applet: ../../src/xcb_io.c:528: _XAllocID: La declaraci\xf3n `ret != inval_id' no se cumple.")

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 77: ordinal not in range(128)

To post a comment you must log in.
Revision history for this message
Evan (ev) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'errors/api/resources.py'
2--- errors/api/resources.py 2013-06-11 17:08:00 +0000
3+++ errors/api/resources.py 2013-06-11 21:02:36 +0000
4@@ -259,7 +259,8 @@
5 if first_appearance:
6 if m.get('FirstSeen', '') != version:
7 continue
8-
9+ if isinstance(bucket, unicode):
10+ bucket = bucket.encode('utf-8')
11 hashed = sha1(bucket).hexdigest()
12 if cassandra.get_problem_for_hash(hashed):
13 href = 'problem/%s' % hashed
14@@ -395,6 +396,8 @@
15 buckets = cassandra.get_package_new_buckets(src_package,
16 previous_version, new_version)
17 for bucket in buckets:
18+ if isinstance(bucket, unicode):
19+ bucket = bucket.encode('utf-8')
20 hashed = sha1(bucket).hexdigest()
21 if cassandra.get_problem_for_hash(hashed):
22 href = 'problem/%s' % hashed

Subscribers

People subscribed via source and target branches

to all changes: