Opened 3 years ago

Closed 3 years ago

#19161 closed Bug (fixed)

Missing clean_password in custom user documentation

Reported by: DavidW Owned by: nobody
Component: Documentation Version: master
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by aaugustin)

https://docs.djangoproject.com/en/dev/topics/auth/#auth-custom-user

class UserChangeForm(forms.ModelForm):
    """A form for updateing users. Includes all the fields on
    the user, but replaces the password field with admin's
    pasword hash display field.
    """
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = MyUser

Needs the following added:

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]

Or you get a not-null constraint violation on form submit.

Change History (6)

comment:1 Changed 3 years ago by lrekucki

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

comment:2 Changed 3 years ago by aaugustin

  • Description modified (diff)

Fixed formatting (please use preview).

comment:3 Changed 3 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 3 years ago by russellm

  • Severity changed from Normal to Release blocker

Actually, this should be a release blocker, since it's a fundamentally misleading piece of documentation in a new feature.

comment:5 Changed 3 years ago by claudep

  • Summary changed from Line missing on Dev documentation to Missing clean_password in custom user documentation

comment:6 Changed 3 years ago by timo

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top