Changes between Version 2 and Version 3 of Ticket #33269


Ignore:
Timestamp:
Nov 5, 2021, 6:02:01 PM (3 years ago)
Author:
lieryan
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33269 – Description

    v2 v3  
    1 A colleague made this error recently doing a user.has_perms("foobar") instead of the correct user.has_perms(["foobar"]) or user.has_perm("foobar"). The code initially appeared to work fine since in Python, str is an iterable that returned individual characters as string when iterated over.
     1A colleague made this error recently doing a `user.has_perms("foobar")` instead of the correct `user.has_perms(["foobar"])` or `user.has_perm("foobar")`. The code initially appeared to work fine since in Python, `str` is an iterable that returned individual characters as string when iterated over.
    22
    3 We checked for str in particular rather than enforcing it to be a list, since perm_list may actually be tuple, set, generators, or other iterables.
     3We checked for `str` in particular rather than enforcing it to be a `list`, since `perm_list` may actually be tuple, set, generators, or other iterables.
    44
    5 An alternative way this could be fixed is to just silently behave like has_perm() if perm_list is actually a string rather than raising an error, but that'll probably enforce a bad habit.
     5An alternative way this could be fixed is to just silently behave like `has_perm()` if `perm_list` is actually a string rather than raising an error, but that'll probably enforce a bad habit.
    66
    77Pull request in  Github (https://github.com/django/django/pull/14969).
Back to Top