Code

Opened 6 years ago

Closed 6 years ago

#7249 closed (invalid)

Better code for 7535 fix

Reported by: leotr Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

-                    users = list(User.objects.filter(email=username))
-                    if len(users) == 1:
-                        user = users[0]
-                    else:
-                        # Either we cannot find the user, or if more than 1
-                        # we cannot guess which user is the correct one.
-                        raise User.DoesNotExist()

I think that mine is more elegant. Just add AssertionError to exception list.

Attachments (1)

1.diff (1.2 KB) - added by leotr 6 years ago.

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by leotr

comment:1 Changed 6 years ago by leotr

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by leotr

  • Triage Stage changed from Unreviewed to Design decision needed

In other words i don't see a reason to evaluate a query and then check the length of list. The AssertionError is raised when more than 1 object exist.

comment:3 Changed 6 years ago by leotr

  • Resolution set to invalid
  • Status changed from new to closed

Invalid after changeset 7536

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.