Fix up some string types.
Review Request #12106 — Created March 7, 2022 and submitted
This change fixes up a handful of issues related to string types. Some
of these are more important than others.For a couple places, we had code deep in the diff rendering which was
creating aSafeString
. Because we have caching at many levels in the
diff viewer, these values would end up trying to go through pickle to
store the rendered data. When pickle encounters a value that it doesn't
understand, it tries to callstr()
on it. With the older Django
version, this would correctly convert, but with the modern Django,
callingstr()
on aSafeString
would return theSafeString
again.
This would just end up infinitely recursing inside of the pickle
machinery. There are two places where this affects. For the first, the
fix is to remove some oldmark_safe
calls. For the second (where we
were rendering a template), the solution is to explicitly convert to
str
by using a slice trick.Next, the HTTP digest authentication backend was calling MD5, but
passing in anstr
instead ofbytes
. We also had a handful of other
places where there was some confusion about bytes/str which was found
via static analysis.Finally, a bunch of unit tests were passing in
int
types for the
revision when creating test filediffs. These do end up getting cast to
str, but since we say the type of the argument is str, it's more correct
to pass that in directly.
- Created a review request with a diff and was able to successfully load
the diff viewer page. - Ran unit tests.
Summary | ID |
---|---|
86d3e35c2eb070ba7f85322b7a2f68338915c9ff |
Description | From | Last Updated |
---|---|---|
I saw the bit in the description about this, but I really don't like it. This is a valid part … |
chipx86 |
- Description:
-
This change fixes up a handful of issues related to string types. Some
of these are more important than others. For a couple places, we had code deep in the diff rendering which was
creating a SafeString
. Because we have caching at many levels in thediff viewer, these values would end up trying to go through pickle to store the rendered data. When pickle encounters a value that it doesn't understand, it tries to call str()
on it. With the older Djangoversion, this would correctly convert, but with the modern Django, calling str()
on aSafeString
would return theSafeString
again.This would just end up infinitely recursing inside of the pickle machinery. There are two places where this affects. For the first, the fix is to remove some old mark_safe
calls. For the second (where wewere rendering a template), the solution is to explicitly convert to str
by using a slice trick.Next, the HTTP digest authentication backend was calling MD5, but
passing in an str
instead ofbytes
. We also had a handful of otherplaces where there was some confusion about bytes/str which was found via static analysis. ~ Finally, a bunch of unit tests were passing in various types of objects
~ (int, Revision) when creating test filediffs. This would end up getting ~ cast appropriately, but was tripping up some tooling. I've changed these ~ to explicitly pass in the strings. ~ Finally, a bunch of unit tests were passing in
int
types for the~ revision when creating test filediffs. These do end up getting cast to ~ str, but since we say the type of the argument is str, it's more correct ~ to pass that in directly. - Commits:
-
Summary ID 2078677af1950aea265e4fd93ae45a3d8471dfdf 86d3e35c2eb070ba7f85322b7a2f68338915c9ff - Diff:
-
Revision 2 (+208 -234)