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.
This commit is contained in:
Nick Pope 2023-11-21 15:37:28 +00:00 committed by Mariusz Felisiak
parent 0257426fe1
commit 174369a990
1 changed files with 3 additions and 7 deletions

View File

@ -9,15 +9,11 @@ from django.utils.functional import Promise
class DjangoUnicodeDecodeError(UnicodeDecodeError): class DjangoUnicodeDecodeError(UnicodeDecodeError):
def __init__(self, obj, *args):
self.obj = obj
super().__init__(*args)
def __str__(self): def __str__(self):
return "%s. You passed in %r (%s)" % ( return "%s. You passed in %r (%s)" % (
super().__str__(), super().__str__(),
self.obj, self.object,
type(self.obj), type(self.object),
) )
@ -72,7 +68,7 @@ def force_str(s, encoding="utf-8", strings_only=False, errors="strict"):
else: else:
s = str(s) s = str(s)
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
raise DjangoUnicodeDecodeError(s, *e.args) raise DjangoUnicodeDecodeError(*e.args) from None
return s return s