Skip to content

Commit 3143be9

Browse files
author
Kevin Michel
committed
Fix #168: Subsegment name serialization causing MissingName error
Django sometimes uses SafeString instead of str for template names. Jsonpickle serializes SafeString as `{ "py/newargs": ["django/forms/widgets/attrs.html"]}` instead of `"django/forms/widgets/attrs.html" which is the reason for the invalid subsegment name.
1 parent 9a11587 commit 3143be9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

aws_xray_sdk/ext/django/templates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from django.template import Template
4+
from django.utils.safestring import SafeString
45

56
from aws_xray_sdk.core import xray_recorder
67

@@ -22,6 +23,10 @@ def xray_render(self, context):
2223
template_name = self.name or getattr(context, 'template_name', None)
2324
if template_name:
2425
name = str(template_name)
26+
# SafeString are not properly serialized by jsonpickle,
27+
# turn them back to str by adding a non-safe str.
28+
if isinstance(name, SafeString):
29+
name += ''
2530
subsegment = xray_recorder.current_subsegment()
2631
if subsegment:
2732
subsegment.name = name

0 commit comments

Comments
 (0)