#33269: Raise an error if a string is passed into has_perms() instead of a list
-------------------------------+--------------------------------------
Reporter: lieryan | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by lieryan:
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.8f3aabc1871bee9d008b3be41dbfeea3%40djangoproject.com.