You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've only tested this with Django 2.2 and python 3.7.5.
When attempting to use the thumbnail templatetag, specifying anchor='c' causes the template to render and cause an infinite recursion error. I've traced this down to the pickling logic to come up with the hash for the cache filename. The pickler includes the anchor value which is a SafeString instance which apparently has fits when pickled. It has to do with SafeString being a subclass of str, but I don't know enough to know why.
One fix would be to check if the kwarg to the templatetag includes the anchor, if it does, convert it to a regular string. However, that looks to be a really ugly hack.
The core problem of SafeString not being able to be pickled properly can be verified with:
fromcopyimportcopyfromhashlibimportmd5frompickleimportPicklerfromioimportBytesIOdefpickle(obj):
file=BytesIO()
Pickler(file, 0).dump(obj)
returnmd5(file.getvalue()).hexdigest()
# Copied from Django's sourceclassSafeData:
def__html__(self):
""" Return the html representation of a string for interoperability. This allows other template engines to understand Django's SafeData. """returnselfclassSafeText(str, SafeData):
""" A str subclass that has been specifically marked as "safe" for HTML output purposes. """def__add__(self, rhs):
""" Concatenating a safe string with another safe bytestring or safe string is safe. Otherwise, the result is no longer safe. """t=super().__add__(rhs)
ifisinstance(rhs, SafeData):
returnSafeText(t)
returntdef__str__(self):
returnselfSafeString=SafeTextx='hello'safe=SafeString(x)
pickle(x)
pickle(safe)
Changing the protocol on the pickler to 3 (the default for python3) does seem to resolve the issue.
The text was updated successfully, but these errors were encountered:
I've only tested this with Django 2.2 and python 3.7.5.
When attempting to use the thumbnail templatetag, specifying
anchor='c'
causes the template to render and cause an infinite recursion error. I've traced this down to the pickling logic to come up with the hash for the cache filename. The pickler includes the anchor value which is aSafeString
instance which apparently has fits when pickled. It has to do with SafeString being a subclass ofstr
, but I don't know enough to know why.One fix would be to check if the kwarg to the templatetag includes the anchor, if it does, convert it to a regular string. However, that looks to be a really ugly hack.
The core problem of
SafeString
not being able to be pickled properly can be verified with:Changing the protocol on the pickler to 3 (the default for python3) does seem to resolve the issue.
The text was updated successfully, but these errors were encountered: