Code

Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#19807 closed Bug (fixed)

Creating a superuser doesn't work

Reported by: Semmel Owned by: claudep
Component: Core (Management commands) Version: master
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When syncdb asks if it should create a superuser it fails right after the password.

TypeError: must be char, not unicode

Attachments (1)

19807-1.diff (1.9 KB) - added by claudep 14 months ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 14 months ago by claudep

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

Could you please tell us:

  • your OS and Python version
  • what version of Django code are you running exactly (1.5rc1, 1.5 HEAD, master)?
  • the output of the command error with the --traceback option

comment:2 Changed 14 months ago by claudep

  • Component changed from Uncategorized to Core (Management commands)
  • Severity changed from Release blocker to Normal

We have no sufficient information to set the release blocker flag, unless more details are provided.

comment:3 Changed 14 months ago by Semmel

I'm running Django master on Windows 7 with Python 2.7.2 - traceback is as follows:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 240,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 283,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 413,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 109, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 195,
in emit_post_sync_signal
    interactive=interactive, db=db)
  File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py", line 182,
in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:\Python27\lib\site-packages\django\contrib\auth\management\__init__.py
", line 117, in create_superuser
    call_command("createsuperuser", interactive=True, database=db)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
161, in call_command
    return klass.execute(*args, **defaults)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 283,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\contrib\auth\management\commands\cr
eatesuperuser.py", line 125, in handle
    password2 = getpass.getpass('Password (again): ')
  File "C:\Python27\lib\getpass.py", line 95, in win_getpass
    msvcrt.putch(c)
TypeError: must be char, not unicode

I guess this is a Windows-only problem. I'll investigate further.

comment:4 Changed 14 months ago by Semmel

Just wanted to note that this seems to be a Windows-only and non-Django problem.
The error occurs if you use unicode_literals in conjunction with a custom prompt for getpass.

from __future__ import unicode_literals
import getpass

password = getpass.getpass()
password2 = getpass.getpass('Password (again): ')

comment:5 Changed 14 months ago by aaugustin

  • Severity changed from Normal to Release blocker
  • Triage Stage changed from Unreviewed to Accepted

Django should use force_str on the prompt before calling getpass.

Marking as a release blocker again since it appears to be related to unicode_literals, which is a change in 1.5.

comment:6 Changed 14 months ago by claudep

  • Owner changed from nobody to claudep
  • Status changed from new to assigned

Changed 14 months ago by claudep

comment:7 Changed 14 months ago by claudep

  • Has patch set

Would it be possible to test the attached patch?

comment:8 follow-up: Changed 14 months ago by Semmel

I dug into the issue just a little bit further. The problem is that getpass does not support Unicode yet (because it doesn't use the Unicode methods of msvcrt). While this is clearly a Python bug it got introduced during the transition of Django from Python 2.x to Python 3.x - hence I too consider it a release blocker.
But I'm not sure about the fix. What happens when getpass gets fixed? Will it break again? Will the test fail? I would prefer a fix that makes Unicode available as soon as this gets fixed.

I can't test the patch right now. Anybody else able to test it?

comment:9 in reply to: ↑ 8 Changed 14 months ago by claudep

Replying to Semmel:

But I'm not sure about the fix. What happens when getpass gets fixed? Will it break again? Will the test fail? I would prefer a fix that makes Unicode available as soon as this gets fixed.

force_str is converting to bytestring on Python 2, and let the string Unicode on Python 3, so I think we should be safe on this side.

comment:10 Changed 14 months ago by Semmel

Sounds good + the tests run fine. And of course - this fixes the issue. Great work. :)

comment:11 Changed 14 months ago by claudep

  • Triage Stage changed from Accepted to Ready for checkin

Thanks for testing.

comment:12 Changed 14 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 02e5909f7ae436dab8e4d13370670c467163b8aa:

Fixed #19807 -- Sanitized getpass input in createsuperuser

Python 2 getpass on Windows doesn't accept unicode, even when
containing only ascii chars.
Thanks Semmel for the report and tests.

comment:13 Changed 14 months ago by Claude Paroz <claude@…>

In 5921f15c113f41f3baca0b599ccb9dad83649682:

[1.5.x] Fixed #19807 -- Sanitized getpass input in createsuperuser

Python 2 getpass on Windows doesn't accept unicode, even when
containing only ascii chars.
Thanks Semmel for the report and tests.
Backport of 02e5909f7a from master.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.