Opened 16 years ago

Closed 11 years ago

Last modified 11 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: dev
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

Description

(Version 0.97pre)

When I run manage.py 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/manage.py", line 11, in <module>
    execute_manager(settings)
  File "/workspace/laf/django/core/management/__init__.py", line 272, in execute_manager
    utility.execute()
  File "/workspace/laf/django/core/management/__init__.py", line 219, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/workspace/laf/django/core/management/base.py", line 72, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/workspace/laf/django/core/management/base.py", line 86, in execute
    output = self.handle(*args, **options)
  File "/workspace/laf/django/core/management/base.py", line 168, in handle
    return self.handle_noargs(**options)
  File "/workspace/laf/django/core/management/commands/syncdb.py", line 97, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive)
  File "//workspace/laf/django/core/management/sql.py", line 491, in emit_post_sync_signal
    verbosity=verbosity, interactive=interactive)
  File "/workspace/laf/django/dispatch/dispatcher.py", line 360, in send
    **named
  File "/workspace/laf/django/dispatch/robustapply.py", line 47, in robustApply
    return receiver(*arguments, **named)
  File "/workspace/laf/django/contrib/auth/management.py", line 45, in create_superuser
    do_create()
  File "/workspace/laf/django/contrib/auth/create_superuser.py", line 73, in createsuperuser
    password = getpass.getpass()
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/getpass.py", 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('')
else:
   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 by edgarsj, 16 years ago

Component: Uncategorizeddjango-admin.py
Keywords: feature added
Triage Stage: UnreviewedDesign decision needed

I vote +0 on this one

comment:2 by Marc Fargas, 16 years ago

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 by Luke Plant, 14 years ago

Severity: Normal
Type: New feature

comment:4 by Alex Gaynor, 13 years ago

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 by AeroNotix, 11 years ago

Owner: changed from nobody to AeroNotix
Status: newassigned

comment:7 by AeroNotix, 11 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:8 by Baptiste Mispelon, 11 years ago

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 by Baptiste Mispelon <bmispelon@…>, 11 years ago

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 by Baptiste Mispelon, 11 years ago

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

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

I'm looking into it.

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