Opened 26 hours ago

Closed 25 hours ago

#37202 closed Bug (duplicate)

MinimumLengthValidator.get_error_message has a bug that breaks translation

Reported by: meng Owned by:
Component: contrib.auth Version: 5.2
Severity: Normal Keywords:
Cc: meng Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,
The get_error_message method of the MinimumLengthValidator class in Django's auth password_validation.py file has a bug that prevents translations from working correctly.

The problem code is:

class MinimumLengthValidator:
    ...
    def get_error_message(self):
        return (
            ngettext(
                "This password is too short. It must contain at least %d character.",
                "This password is too short. It must contain at least %d characters.",
                self.min_length,
            )
            % self.min_length
        )

The correct code should be:

class MinimumLengthValidator:
    ...
    def get_error_message(self):
        return (
            ngettext(
                "This password is too short. It must contain at least %(min_length)d character.",
                "This password is too short. It must contain at least %(min_length)d characters.",
                self.min_length,
            )
            % {"min_length": self.min_length}
        )

Attachments (1)

password_validation.py (9.4 KB ) - added by meng 26 hours ago.

Download all attachments as: .zip

Change History (2)

by meng, 26 hours ago

Attachment: password_validation.py added

comment:1 by meng, 25 hours ago

Resolution: duplicate
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top