Code

Opened 6 years ago

Closed 2 months ago

Last modified 2 months 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

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.

Attachments (0)

Change History (10)

comment:1 Changed 6 years ago by edgarsj

  • Component changed from Uncategorized to django-admin.py
  • Keywords feature added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

I vote +0 on this one

comment:2 Changed 6 years ago by telenieko

  • 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 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:4 Changed 3 years ago by Alex

  • Easy pickings unset
  • Triage Stage changed from Design decision needed to Accepted
  • 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 2 months ago by AeroNotix

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

comment:7 Changed 2 months ago by AeroNotix

  • Has patch set
  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 2 months ago by bmispelon

  • Triage Stage changed from Ready for checkin to Accepted

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

comment:9 Changed 2 months ago by Baptiste Mispelon <bmispelon@…>

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

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 2 months ago by bmispelon

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.

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.