#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         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  1
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33269>
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/050.87264ec2f6bbf13730a7e3b9563d9027%40djangoproject.com.

Reply via email to