Opened 8 years ago

Closed 6 years ago

#9598 closed (wontfix)


Reported by: to.roma.from.djbug@… Owned by: nobody
Component: contrib.auth Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



class UserManager(models.Manager):
    def create_user(self, username, email, password=None):
        "Creates and saves a User with the given username, e-mail and password."
        now =
        user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)
        if password:
        return user

This should support keyword arguments for first_name, last_name etc. That would make user-creating code cleaner and would avoid unnecessary database operations. The change is so obvious I’m not including a patch.

Are there any reasons not to add such a feature?

Change History (5)

comment:1 Changed 8 years ago by Malcolm Tredinnick

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

At that point it's no different form create() with a call to set_password(), so you might as well use that version if you need to add all the extra fields. I'm in favour of keeping create_user() nice and simple to document and memorise.

comment:2 Changed 8 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 8 years ago by dc

-1 for the change. Can already be achieved with

user = User(**kwargs)

comment:4 Changed 8 years ago by Roman Odaisky

dc, I think you’re missing the point. From your reasoning one might conclude the create_user method should be removed as well, and maybe Django should not exist because Web sites can already be achieved with other means? Python is a great language because it allows concise code, and having one statement do the job of three would be beneficial IMO.

Alternate proposal

On second thoughts, I’ve come up with a solution which is closer to Django spirit. What’s the problem with create_user? Its save() is needless if more fields are to be populated. So let’s just add a ‘commit’ argument, default True, that would control whether save() is called. This would be immediately familiar to any Django user.

At the same time, additional arguments don’t really hinder one’s ability to memorise. One has to memorise when one needs things that don’t work, not when one doesn’t need things that would work.

comment:5 Changed 6 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed
Summary: create_user should allow specifying more fields`

Not worth the change. As noted above, if you want to control everything, just create the user model directly and call set_password. The issue of why then to keep create_user is moot. It causes no harm (and is used in many places) by being there, so it's not going away.

Note: See TracTickets for help on using tickets.
Back to Top