Changes between Version 2 and Version 3 of Ticket #33269
- Timestamp:
- Nov 5, 2021, 6:02:01 PM (3 years ago)
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, stris an iterable that returned individual characters as string when iterated over.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. 2 2 3 We checked for str in particular rather than enforcing it to be a list, since perm_listmay actually be tuple, set, generators, or other iterables.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. 4 4 5 An alternative way this could be fixed is to just silently behave like has_perm() if perm_listis actually a string rather than raising an error, but that'll probably enforce a bad habit.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. 6 6 7 7 Pull request in Github (https://github.com/django/django/pull/14969).