Opened 12 years ago

Closed 9 years ago

Last modified 9 years ago

#19665 closed Bug (fixed)

'Command' object has no attribute 'stderr'

Reported by: Stefan Kögl Owned by: Claude Paroz
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: mike@… 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 running some self-written management commands with the current stable/1.5.x branch (currently d571894fc09b34b8b43cb8f1790c743a47679851), I get the following AttributeError

$ ./manage.py assign-upload-timestamps
/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py:219: DeprecationWarning: You have no filters defined on the 'mail_admins' logging handler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logged
  DeprecationWarning)

Traceback (most recent call last):
  File "./manage.py", line 36, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 469, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 226, in run_from_argv
    self.stderr.write('%s: %s' % (e.__class__.__name__, e))
AttributeError: 'Command' object has no attribute 'stderr'

As no part of the trace refers to code of my application, I assume a bug in Django 1.5.

Attachments (1)

19665-1.diff (2.3 KB ) - added by Claude Paroz 12 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Claude Paroz, 12 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 by Claude Paroz, 12 years ago

I'm still curious to know what error did your command raises so as self.stderr was not even initialized, as it is one of the first thing execute is doing. Try to replace self.stderr by sys.stderr in your Django code to find out.

by Claude Paroz, 12 years ago

Attachment: 19665-1.diff added

comment:3 by Claude Paroz, 12 years ago

Has patch: set

Patch attached in case someone wants to quickly review it.

comment:4 by Simon Charette, 12 years ago

Triage Stage: AcceptedReady for checkin
Version: 1.5-alpha-1master

Patch looks good and admin_scripts tests pass on Python 2.7.3 and 3.2.3 (SQlite) while the additional test fails without the fix.

Last edited 12 years ago by Simon Charette (previous) (diff)

comment:5 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In b9c8bbf3726a1956be1db70ffd3bef04a2e5311a:

Fixed #19665 -- Ensured proper stderr output for Command.run_from_argv

Thanks Stefan Koegl for the report and Simon Charette for the review.

comment:6 by Claude Paroz <claude@…>, 12 years ago

In 2d8b0315f46d24c6567a05422bd609f3a689bda8:

[1.5.x] Fixed #19665 -- Ensured proper stderr output for Command.run_from_argv

Thanks Stefan Koegl for the report and Simon Charette for the review.
Backport of b9c8bbf37 from master.

comment:7 by Claude Paroz <claude@…>, 12 years ago

In 2d8b0315f46d24c6567a05422bd609f3a689bda8:

[1.5.x] Fixed #19665 -- Ensured proper stderr output for Command.run_from_argv

Thanks Stefan Koegl for the report and Simon Charette for the review.
Backport of b9c8bbf37 from master.

comment:8 by Mike Pelley, 9 years ago

Cc: mike@… added
Resolution: fixed
Status: closednew

I believe I'm having this same problem again with 1.9.5 (see below). I took a brief look at the code and perhaps the fix for #23663 reverted the fix for this bug, although my review was superficial so I might have that wrong. In the error below, I raised the CommandError exception explicitly after discovering a data validation error.

(virtualenv3) mike@rhea:~/Workspace/auris-server/auris$ ./manage.py load_systems ../populated.json 
Traceback (most recent call last):
  File "/home/mike/Workspace/virtualenv3/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mike/Workspace/virtualenv3/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/mike/Workspace/auris-server/auris/db/management/commands/load_systems.py", line 44, in handle
    self._validate_fields()
  File "/home/mike/Workspace/auris-server/auris/db/management/commands/load_systems.py", line 24, in _validate_fields
    '{2})'.format(field, data['name'], system_id))
django.core.management.base.CommandError: Unknown field "alignment" present in system id 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mike/Workspace/virtualenv3/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/mike/Workspace/virtualenv3/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mike/Workspace/virtualenv3/lib/python3.4/site-packages/django/core/management/base.py", line 357, in run_from_argv
    self.stderr.write('%s: %s' % (e.__class__.__name__, e))
AttributeError: 'Command' object has no attribute 'stderr'
Last edited 9 years ago by Tim Graham (previous) (diff)

comment:9 by Tim Graham, 9 years ago

Resolution: fixed
Status: newclosed

Rather than reopening a 3 year old ticket, please open a new one and include a test case for Django's test suite or a sample project to reproduce the issue. Thanks!

comment:10 by Claude Paroz, 9 years ago

Mike, my guess is that your command overrode the __init__ method of the command without calling the super __init__.

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