Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
14ea8857
authored
Oct 18, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: fix UnicodeDecodeError in activitycontextimpl()
Closes #338
parent
6841cc02
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletions
+29
-1
circle/common/models.py
+9
-1
circle/common/tests/test_models.py
+20
-0
No files found.
circle/common/models.py
View file @
14ea8857
...
...
@@ -49,7 +49,15 @@ class WorkerNotFound(Exception):
pass
def
get_error_msg
(
exception
):
try
:
return
unicode
(
exception
)
except
UnicodeDecodeError
:
return
unicode
(
str
(
exception
),
encoding
=
'utf-8'
,
errors
=
'replace'
)
def
activitycontextimpl
(
act
,
on_abort
=
None
,
on_commit
=
None
):
result
=
None
try
:
try
:
yield
act
...
...
@@ -62,7 +70,7 @@ def activitycontextimpl(act, on_abort=None, on_commit=None):
result
=
create_readable
(
ugettext_noop
(
"Failure."
),
ugettext_noop
(
"Unhandled exception:
%(error)
s"
),
error
=
unicode
(
e
))
error
=
get_error_msg
(
e
))
raise
except
:
logger
.
exception
(
"Failed activity
%
s"
%
unicode
(
act
))
...
...
circle/common/tests/test_models.py
View file @
14ea8857
...
...
@@ -22,6 +22,7 @@ from mock import MagicMock
from
.models
import
TestClass
from
..models
import
HumanSortField
from
..models
import
activitycontextimpl
class
MethodCacheTestCase
(
TestCase
):
...
...
@@ -80,3 +81,22 @@ class TestHumanSortField(TestCase):
test_result
=
HumanSortField
.
get_normalized_value
(
obj
,
val
)
self
.
assertEquals
(
test_result
,
result
)
class
ActivityContextTestCase
(
TestCase
):
class
MyException
(
Exception
):
pass
def
test_unicode
(
self
):
act
=
MagicMock
()
gen
=
activitycontextimpl
(
act
)
gen
.
next
()
with
self
.
assertRaises
(
self
.
MyException
):
gen
.
throw
(
self
.
MyException
(
u'test
\xe1
'
))
def
test_str
(
self
):
act
=
MagicMock
()
gen
=
activitycontextimpl
(
act
)
gen
.
next
()
with
self
.
assertRaises
(
self
.
MyException
):
gen
.
throw
(
self
.
MyException
(
'test
\xbe
'
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment