What does the community think to Carlton's take on auth.User?

I enjoyed reading Carlton’s latest Stack Report on where to take the auth.User model. He makes a solid case and outlines some next steps.

In this topic I would want to focus on the documentation changes he suggests. Specifically:

  1. Remove the recommendation of requiring a custom User
  2. Tone down the warning about mid-project migrations
  3. Add a User Profile “How-To” section
  4. (One from me) - Broadly document the steps required for a mid project migration.

These seem like reasonable first steps that on the face of it don’t appear to be too contentious?

12 Likes

Thanks @nanorepublica.

Just to be clear, I think steps 1 and 2 there are exhausted by something along the lines of the draft PR I’ve put up here:

I hope that’s not too radical for anyone :sweat_smile:

To quote the Action Points at the very end of the essay you linked:

At the least I’d like us to remove the highly recommended line about custom user models. Even if you think I’m mad, you must see that having that there is harmful for beginners.

At the same time we should tone down the warning about migrating to a custom user model mid-project. I’ve argued there’s no reason to do it, but even so, it’s not that hard. We can say it’s involved, without giving people heart attacks.

I’d hope we could get that far at least.

My plan is to recruit @wsvincent to lead author the Profile How To at DjangoCon this year :stuck_out_tongue_winking_eye:

4 Likes

(Gotta do a little bike-shedding here)
I’d love to see you drop the word “somewhat” in the second change.

I agree that in many cases, changing the user model isn’t horrible - but there are also a number of cases where it becomes a nightmare. (Usually when things weren’t done “right” at the start, but then we don’t always do things perfect at the beginning.)

I’d love to see some type of wording (without it becoming too long) that expresses the idea that it might be a simple operation, or it could end up being extremely complex.

No objections to that @KenWhitesell :wink:

@cartlon I’m happy to do a docs version of this basically: Django UserProfile Model | LearnDjango.com

Just need to know that people want it :slight_smile:

6 Likes

These all seem like reasonable steps to be made. 3 and 4 can be done separately and don’t need to be part of a larger User re-imagining either.

Regarding 4, I’m not sure of the process of how to add those more advanced guides to the docs. I’d like to see it done. I suspect the first step is write a blog post that shows it, get feedback, then attempt a upstream merge of it?

2 Likes

On point 4 I have seen this article referenced in the past.

It’s probably a good starting point for it.

2 Likes

Just passing through to +1 this & do some bike-shedding of my own on that PR :eyes:

2 Likes

I was finally able to complete the reading of Carlton’s post, and I can’t agree more with what he suggests/proposes.

With my non-Fellow hat on, let me share that I have always been critical of the “custom user model option” and, in all honesty, never fully grasped it (or used it). I always preferred to use 1-1 profiles to do what I needed, and I see the User model as a mere placeholder for the “entity that represents an authenticated being”. This means I heavily rely on User for everything authentication-related, but any metadata or logic beyond that is in a new model with a 1-1 to User.

What I don’t see mentioned in the article (and I think I understand why – the article is about the User model and improvements for it, not a whole redesign) is how to support, nicely, decoupled authentication (“Is this user who they say they are?”) and authorization (“Can this user perform action X?”) flows. This is something I would eventually love to see improved in Django.

In summary, I’m +1 to the immediate changes, including:

  • Proposed docs changes (will do that PR review soonish)
  • Pushing for a Profile How-To

A medium-term initiative would be evaluating and including in core django-unique-user-email, which I haven’t inspected yet.

In the medium to long term, I’m +1 on working on a plan where custom User models get deprecated-ish or documented as a last resort.

4 Likes

Thanks @nessita.

Following the discussion, various posts online, and the numerous hearts and +1s, here and on the PR, I’ve opened two Django tickets to push forward the small docs changes, and the Profile How-To.

https://code.djangoproject.com/ticket/35767

I updated the PR for this, to take into account the feedback, and rebased, ready for review.

https://code.djangoproject.com/ticket/35768

@wsvincent I assigned you this one based on your reply above. Looking forward to chatting with you about it about DjangoCon.

Thanks all. :gift:

3 Likes

I think it’s worth pointing out the 2012 Wiki on this topic and the fact that Option #5, which @jacobian liked at the time, was in line with this: ContribAuthImprovements – Django

Further context here: Upgrading auth.User - the profile approach · GitHub

2 Likes

Just wanted to drop a quick +1 to this topic.

I agree with basically everything Carlton wrote and especially having a plug-and-play way of switching auth methods from username to email to [your-solution] would be amazing.

1 Like

I agree with that. Oddly enough, if you actually read the Customizing authentication in Django | Django documentation | Django it no longer is “highly recommended”, but rather wary: “stop to consider if this is the right choice”. :slight_smile:

I agree with this, with a bit of a caveat.

What I really want to see is good support for using different types of identifiers for logging in. I will go with the email example because it’s what I personally use almost always.

Without needing a second model or a custom user, how would I do the following:

  • Have the login identifier be an email field, with correct length and validation?
  • Ideally enforce in this in the database via constraints, e.g. that the email is case-insensitively unique?
  • Related to the above, ensure I can query on it quickly?

I’m also interested in how we’d add extra (but very auth related) bells and whistles, for example:, storing that the email has been verified, but separate from is_active.

And finally if this would include a plan to remove (optionally? over an extended deprecation?) the non-auth related fields, especially first/last name.

Most of these things are addressed in your post. But I would be against, for example, having both a username and email but only using one of them. I would like to see some easy to use options where you can choose which you want to live in the database (which should include either or both). Which leaves me wondering how to do this. With extra models and User is close to empty? Could work.

But I do agree with all of the immediate action points, which is what this post is about anyway :slight_smile:

Sorry, a bit rambly, could have been more concise.

5 Likes

Yes, they are :slightly_smiling_face:, but let me just say what I think, to be clear.

Ultimately I would strip User down to (more or less) just an ID field to be the target of foreign keys from other models. Authentication credentials (be it log in by username, email, or anything else) should live in separate models, so you can add whichever you need, with Django providing the base interface, and then the core implementations that are most common.

We’re a long way from there, so it’s a question of slowly slowly. Current status is proof-of-concepts showing that we can evolve auth.User. It’s been a long-time held that we just simply couldn’t, and I think that’s where we gave up too early. (An in the meantime strategy I’m quite keen on is just ignoring offending fields, and assuming we already got there, of course.)

1 Like

From what I can tell, accepted tickets exist for all of the proposed points I outlined in the original ticket (either new or existing)

  1. (& 2) #35767 (Don't recommend using a custom user model when starting a new project) – Django
  2. #35768 (Add a User Profile How-To to docs) – Django
  3. #25313 (Document how to migrate from a built-in User model to a custom User model) – Django

Can we lock this topic as I would suggest that any further discussion be focused in a new topic for any other changes?

2 Likes