Merge pull request #379 from aadamson/warning-details-dumps-check

Check that we can serialize the warning detail attr
This commit is contained in:
Bruno Oliveira
2019-01-11 15:17:02 -02:00
committed by GitHub
3 changed files with 45 additions and 1 deletions

View File

@@ -218,7 +218,15 @@ def serialize_warning_message(warning_message):
for attr_name in warning_message._WARNING_DETAILS:
if attr_name in ("message", "category"):
continue
result[attr_name] = getattr(warning_message, attr_name)
attr = getattr(warning_message, attr_name)
# Check if we can serialize the warning detail, marking `None` otherwise
# Note that we need to define the attr (even as `None`) to allow deserializing
try:
dumps(attr)
except DumpError:
result[attr_name] = repr(attr)
else:
result[attr_name] = attr
return result