From 174369a990c00d75cf40e0a06ab82bec9a89a7ef Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Tue, 21 Nov 2023 15:37:28 +0000 Subject: [PATCH] Refs #34986 -- Avoided pickling error in DjangoUnicodeDecodeError. By using the existing object reference instead of a custom one, pickling related issues when running the test suite in parallel can be avoided. --- django/utils/encoding.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 5986993759..e57e2a2ba1 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -9,15 +9,11 @@ from django.utils.functional import Promise class DjangoUnicodeDecodeError(UnicodeDecodeError): - def __init__(self, obj, *args): - self.obj = obj - super().__init__(*args) - def __str__(self): return "%s. You passed in %r (%s)" % ( super().__str__(), - self.obj, - type(self.obj), + self.object, + type(self.object), ) @@ -72,7 +68,7 @@ def force_str(s, encoding="utf-8", strings_only=False, errors="strict"): else: s = str(s) except UnicodeDecodeError as e: - raise DjangoUnicodeDecodeError(s, *e.args) + raise DjangoUnicodeDecodeError(*e.args) from None return s