Opened 15 years ago
Closed 15 years ago
#12593 closed (duplicate)
"manage.py loaddata" exits with system exist status 0 when there are errors
Reported by: | bruce_s | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
"manage.py loaddata" returns with system exit status 0 on error. it should return nonzero on error,
so that (for example) it plays nice with ant, make, expect, etc.
Example:
% ./manage.py loaddata gamedata-test.json Installing json fixture 'gamedata-test' from absolute path. Problem installing fixture 'gamedata-test.json': Traceback (most recent call last): File "/usr/lib64/python2.6/site-packages/django/core/management/commands/loaddata.py", line 150, in handle for obj in objects: File "/usr/lib64/python2.6/site-packages/django/core/serializers/json.py", line 41, in Deserializer for obj in PythonDeserializer(simplejson.load(stream)): File "/usr/lib64/python2.6/json/__init__.py", line 267, in load parse_constant=parse_constant, **kw) File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode obj, end = self._scanner.iterscan(s, **kw).next() File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan rval, next_pos = action(m, context) File "/usr/lib64/python2.6/json/decoder.py", line 219, in JSONArray raise ValueError(errmsg("Expecting object", s, end)) ValueError: Expecting object: line 2 column 5 (char 6) % echo $? 0
The code at fault is in /django/core/management/commands/loaddata.py, around line 170 (and in several other places),
where there are try/except blocks which return when they should either sys.exit(1) or raise, so that the outermost program
knows to exit with error:
except Exception: import traceback fixture.close() transaction.rollback() transaction.leave_transaction_management() if show_traceback: traceback.print_exc() else: sys.stderr.write( self.style.ERROR("Problem installing fixture '%s': %s\n" % (full_path, ''.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))))) return
That last "return" is the bug. Replacing it with "raise" fixes the problem but makes the output quite a bit messier:
% ./manage.py loaddata gamedata-test.json Installing json fixture 'gamedata-test' from absolute path. Problem installing fixture 'gamedata-test.json': Traceback (most recent call last): File "/usr/lib64/python2.6/site-packages/django/core/management/commands/loaddata.py", line 150, in handle for obj in objects: File "/usr/lib64/python2.6/site-packages/django/core/serializers/json.py", line 41, in Deserializer for obj in PythonDeserializer(simplejson.load(stream)): File "/usr/lib64/python2.6/json/__init__.py", line 267, in load parse_constant=parse_constant, **kw) File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode obj, end = self._scanner.iterscan(s, **kw).next() File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan rval, next_pos = action(m, context) File "/usr/lib64/python2.6/json/decoder.py", line 219, in JSONArray raise ValueError(errmsg("Expecting object", s, end)) ValueError: Expecting object: line 2 column 5 (char 6) Traceback (most recent call last): File "./manage.py", line 11, in <module> execute_manager(settings) File "/usr/lib64/python2.6/site-packages/django/core/management/__init__.py", line 439, in execute_manager utility.execute() File "/usr/lib64/python2.6/site-packages/django/core/management/__init__.py", line 380, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 222, in execute output = self.handle(*args, **options) File "/usr/lib64/python2.6/site-packages/django/core/management/commands/loaddata.py", line 200, in handle transaction.leave_transaction_management() File "/usr/lib64/python2.6/site-packages/django/db/transaction.py", line 74, in leave_transaction_management raise TransactionManagementError("This code isn't under transaction management") django.db.transaction.TransactionManagementError: This code isn't under transaction management % echo $? 1
The other option is to change the return to sys.exit(1):
% ./manage.py loaddata gamedata-test.json Installing json fixture 'gamedata-test' from absolute path. Problem installing fixture 'gamedata-test.json': Traceback (most recent call last): File "/usr/lib64/python2.6/site-packages/django/core/management/commands/loaddata.py", line 150, in handle for obj in objects: File "/usr/lib64/python2.6/site-packages/django/core/serializers/json.py", line 41, in Deserializer for obj in PythonDeserializer(simplejson.load(stream)): File "/usr/lib64/python2.6/json/__init__.py", line 267, in load parse_constant=parse_constant, **kw) File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode obj, end = self._scanner.iterscan(s, **kw).next() File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan rval, next_pos = action(m, context) File "/usr/lib64/python2.6/json/decoder.py", line 219, in JSONArray raise ValueError(errmsg("Expecting object", s, end)) ValueError: Expecting object: line 2 column 5 (char 6) % echo $? 1
Patch to fix with sys.exit(1):
--- loaddata.py 2010-01-12 10:54:47.000000000 -0800
+++ /usr/lib64/python2.6/site-packages/django/core/management/commands/loaddata.py 2010-01-12 10:54:17.000000000 -0800
@@ -105,7 +105,7 @@ class Command(BaseCommand):
+ return
@@ -138,7 +138,7 @@ class Command(BaseCommand):
+ return
@@ -167,7 +167,7 @@ class Command(BaseCommand):
+ return
@@ -178,7 +178,7 @@ class Command(BaseCommand):
+ return