fix non standard implementation of __getattr__#675
fix non standard implementation of __getattr__#675mluard wants to merge 2 commits intojazzband:masterfrom
Conversation
|
Not sure if this is backwards compatible, but makes sense. |
|
This will break backwards compatibility in the specific case where you try to access an attribute on a token user instance when that attribute does not exist on the instance itself and does not exist as a key in the token. This is a case that should be handled defensively using an exception handler, a In the case where the name of the attribute is known to always exist on the token, this is not a breaking change. In my case, I was updating the dependencies of an older Django application, and the addition of the |
According to the the docs, a
__getattr__magic method should either return a value for the requested attribute name, or raiseAttributeError.A
__getattr__method was added to theTokenUserclass that allows accessing keys on the token as if they were attributes of theTokenUserclass. In the current implementation, if the requested attribute name is not a key in thetokendictionary, thenNoneis returned instead of raisingAttributeError.When Django's auth backend
ModelBackenddoes permission checks on a user object, it first checks for an attribute named_perm_cachewithhasattr, then builds the cache if it doesn't exist. Sincehasattrincorrectly returnsTruefor aTokenUserinstance, the cache (which would have resolved to an empty set) is never created. This ultimately results in aTypeErrorbecauseNoneis not Iterable.