Opened 2 years ago

Closed 2 years ago

#20694 closed Uncategorized (wontfix)

Non-ascii unicode characters considered invalid in username

Reported by: akhayyat@… Owned by: nobody
Component: contrib.auth Version: 1.5
Severity: Normal Keywords:
Cc: hirokiky@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the admin's user change form, entering a new username with non-ascii unicode characters, e.g. é or ع, and saving the form results in an "Enter a valid username" error message.

The model field accepts such usernames programmatically, but editing a form with such a username prevents saving it unless the username is changed to remove all non-ascii characters.

This pull request fixes the problem, and allows saving the form with non-ascii unicode characters in the username field:

https://github.com/django/django/pull/1322

Change History (3)

comment:1 Changed 2 years ago by hirokiky

  • Cc hirokiky@… added
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset

I sometime use the username as some slugs on URL, like:

http://myservice.co.jp/username/

If the username allow to use Unicode, we will have to use Unicode in the URL.
Non-ASCII url is not allowed on Django, I remember so.

Either allowed or not, this patch should contain some tests and docs.

comment:2 Changed 2 years ago by akhayyat@…

I am unaware of any Django policies, but the non-ASCII username works fine as a slug in a URL for me even without this patch.

The user change form is the only piece I have encountered so far that does not work well with non-ASCII characters.

comment:3 Changed 2 years ago by aaugustin

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

This would be considered a regression for anyone who relies on Django to validate that usernames are ASCII-only.

If "the model field accepts such usernames programmatically", that's just because validation is done in the form layer and not in the model layer.

A custom user model (introduced in 1.5) is the way to go.

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