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.
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/33269>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> 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.
>
> 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.
>
> 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.
New description:
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.
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.
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.
Pull request in [#14969](https://github.com/django/django/pull/14969).
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:1>
Old description:
> 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.
>
> 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.
>
> 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.
>
> Pull request in [#14969](https://github.com/django/django/pull/14969).
New description:
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.
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.
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.
Pull request in Github (https://github.com/django/django/pull/14969).
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:2>
Old description:
> 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.
>
> 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.
>
> 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.
>
> Pull request in Github (https://github.com/django/django/pull/14969).
New description:
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.
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.
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.
Pull request in Github (https://github.com/django/django/pull/14969).
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:3>
* component: Uncategorized => contrib.auth
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:4>
* owner: nobody => lieryan
* needs_better_patch: 0 => 1
* type: Uncategorized => Cleanup/optimization
* status: new => assigned
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:5>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"05cde4764da022ae80e9d7d97ef67c30e896c607" 05cde47]:
{{{
#!CommitTicketReference repository=""
revision="05cde4764da022ae80e9d7d97ef67c30e896c607"
Fixed #33269 -- Made AnonymousUser/PermissionsMixin.has_perms() raise
ValueError on string or non-iterable perm_list.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33269#comment:7>