Add object string representation to truncation warning message

When we print a warning about the value of a CharField being truncated,
print out the string representation of the object so we have a chance of
finding the offending object.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-10-01 16:14:40 +13:00
parent 7710571935
commit 5568ba0ebf

View File

@ -32,7 +32,7 @@ def truncate_charfield_values(sender, instance, *args, **kwargs):
if isinstance(field, models.CharField):
value = getattr(instance, field.name)
if value and len(value) > field.max_length:
logger.warning('%s.%s: length %s exceeds maximum (%s), truncating' % (instance.__class__.__name__, field.name, len(value), field.max_length))
logger.warning('%s.%s: %s: length %s exceeds maximum (%s), truncating' % (instance.__class__.__name__, field.name, str(instance), len(value), field.max_length))
setattr(instance, field.name, value[:field.max_length])