Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hex the bytes value before smart text in bytes fields #195

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/auditlog/diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import unicode_literals
import binascii
import sys

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
Expand Down Expand Up @@ -75,7 +77,11 @@ def get_field_value(obj, field):
value = field.default if field.default is not NOT_PROVIDED else None
else:
try:
value = smart_text(getattr(obj, field.name, None))
field_value = getattr(obj, field.name, None)
# python2 every str is a instance of bytes
if isinstance(field_value, bytes) and sys.version_info > (3, 0):
field_value = binascii.hexlify(field_value)
value = smart_text(field_value)
except ObjectDoesNotExist:
value = field.default if field.default is not NOT_PROVIDED else None

Expand Down