Skip to content

Commit dc99837

Browse files
authored
Fix decode attribute error with options for py3 (#555)
1 parent 6319ebd commit dc99837

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

datadog/dogshell/wrap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ def build_event_body(cmd, returncode, stdout, stderr, notifications):
211211
)
212212

213213
if notifications:
214+
notifications = notifications.decode("utf-8", "replace") if isinstance(notifications, bytes) else notifications
214215
fmt_notifications = u"**>>>> NOTIFICATIONS <<<<**\n\n {notifications}\n".format(
215-
notifications=notifications.decode("utf-8", "replace")
216+
notifications=notifications
216217
)
217218

218219
return \

tests/unit/dogwrap/test_dogwrap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def test_build_event_body(self):
4747
event_body = build_event_body(cmd, returncode, stdout, stderr, notifications)
4848
self.assertEqual(expected_body, event_body)
4949

50+
# notifications can be unicode already in py3, make sure we don't try decoding
51+
notifications = notifications.decode("utf-8", "replace")
52+
event_body = build_event_body(cmd, returncode, stdout, stderr, notifications)
53+
self.assertEqual(expected_body, event_body)
54+
5055
def test_parse_options(self):
5156
options, cmd = parse_options([])
5257
self.assertEqual(cmd, '')

0 commit comments

Comments
 (0)