#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)
Change History (11)
comment:1 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:2 by , 13 years ago
by , 13 years ago
| Attachment: | 19665-1.diff added |
|---|
comment:3 by , 13 years ago
| Has patch: | set |
|---|
Patch attached in case someone wants to quickly review it.
comment:4 by , 13 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|---|
| Version: | 1.5-alpha-1 → master |
Patch looks good and admin_scripts tests pass on Python 2.7.3 and 3.2.3 (SQlite) while failing without the fix.
comment:5 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:8 by , 10 years ago
| Cc: | added |
|---|---|
| Resolution: | fixed |
| Status: | closed → new |
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'
comment:9 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
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 , 10 years ago
Mike, my guess is that your command overrode the __init__ method of the command without calling the super __init__.
I'm still curious to know what error did your command raises so as
self.stderrwas not even initialized, as it is one of the first thingexecuteis doing. Try to replaceself.stderrbysys.stderrin your Django code to find out.