Opened 11 years ago

Closed 5 years ago

Last modified 5 years ago

#7423 closed New feature (fixed)

syncdb fails to read in password in eclipse when creating database

Reported by: galaxy4sale@… Owned by: AeroNotix
Component: Core (Management commands) Version: master
Severity: Normal Keywords: post10
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


(Version 0.97pre)

When I run syncdb to create a new database within eclipse, it fails when it tries to read in a password. Here is the output:

Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table lostitems_lostitem
Creating table django_admin_log
Creating table registration_registrationprofile

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'foo'): admin
E-mail address: foo@bar.baz
Traceback (most recent call last):
  File "/workspace/laf/laf/", line 11, in <module>
  File "/workspace/laf/django/core/management/", line 272, in execute_manager
  File "/workspace/laf/django/core/management/", line 219, in execute
  File "/workspace/laf/django/core/management/", line 72, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/workspace/laf/django/core/management/", line 86, in execute
    output = self.handle(*args, **options)
  File "/workspace/laf/django/core/management/", line 168, in handle
    return self.handle_noargs(**options)
  File "/workspace/laf/django/core/management/commands/", line 97, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive)
  File "//workspace/laf/django/core/management/", line 491, in emit_post_sync_signal
    verbosity=verbosity, interactive=interactive)
  File "/workspace/laf/django/dispatch/", line 360, in send
  File "/workspace/laf/django/dispatch/", line 47, in robustApply
    return receiver(*arguments, **named)
  File "/workspace/laf/django/contrib/auth/", line 45, in create_superuser
  File "/workspace/laf/django/contrib/auth/", line 73, in createsuperuser
    password = getpass.getpass()
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/", line 32, in unix_getpass
    old = termios.tcgetattr(fd)     # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')

After I researched this problem, i found that it is because the input stream is not tty in eclipse, which the getpass() call is expecting. An easy workaround is to just read from stdin if it is not a tty stream.
This will look something like:

if os.isatty(sys.stdin.fileno()):
   p = getpass.getpass('')
   print 'Password: '
   p = sys.stdin.readline().rstrip()

However, this will cause the password to be echoed as the user is typing it in. The patch is fairly quick, and I can provide one if this is the way you want to go.

Change History (10)

comment:1 Changed 11 years ago by edgarsj

Keywords: feature added
Triage Stage: UnreviewedDesign decision needed

I vote +0 on this one

comment:2 Changed 11 years ago by Marc Fargas

Keywords: post10 added; feature removed

But would allow people to script syncdb :))
Anyway, could you provide a patch (as yes, it's the way to go).

And then bring this to django-developers as having the password echoed is not something than can be accepted without a bit deliberation :) (*after* 1.0 if you don't mind).

comment:3 Changed 8 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:4 Changed 7 years ago by Alex Gaynor

Easy pickings: unset
Triage Stage: Design decision neededAccepted
UI/UX: unset

Discussion with carl: marking as accepted, because it should be possible to use syncdb on a non-tty. however printing passwords on screen is not acceptable, a more appropriate behavior would be to skip user creation entirely, and give them a pointer to the createsuperuser command.

comment:5 Changed 5 years ago by AeroNotix

Owner: changed from nobody to AeroNotix
Status: newassigned

comment:7 Changed 5 years ago by AeroNotix

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:8 Changed 5 years ago by Baptiste Mispelon

Triage Stage: Ready for checkinAccepted

The "ready for checkin" flag is for when someone else has reviewed your patch and deemed it ready.

comment:9 Changed 5 years ago by Baptiste Mispelon <bmispelon@…>

Resolution: fixed
Status: assignedclosed

In a7639722f57eebc71cd396512e1fe5c86bebbf15:

Fixed #7423 -- Skip superuser creation when not running in a TTY.

Thanks to trac user galaxy4sale for the original report
and to AeroNotix for the patch.

comment:10 Changed 5 years ago by Baptiste Mispelon

For reference, this commit makes two tests fail when you run the test suite this way (caught by our CI server):

./ django.contrib.auth < /dev/null

I'm looking into it.

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