Opened 17 years ago
Closed 17 years ago
#6420 closed (fixed)
Option show_traceback in loaddata.py causes problems with transactions on exceptions
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Option show_traceback in loaddata does not work properly - instead of correct traceback TransactionManagementError is displayed.
Option show_traceback was introduced in this commit:
http://code.djangoproject.com/changeset/6936
Relevant parts of code that cause this problem:
78 try: ... 93 try: ... 100 except Exception, e: 101 fixture.close() 102 transaction.rollback() 103 transaction.leave_transaction_management() 104 if show_traceback: 105 raise 106 sys.stderr.write( 107 self.style.ERROR("Problem installing fixture '%s': %s\n" % 108 (full_path, str(e)))) 109 return 110 fixture.close() 111 except: 112 if verbosity > 2: 113 print "No %s fixture '%s' in %s." % \ 114 (format, fixture_name, humanize(fixture_dir)) ... 124 transaction.commit() 125 transaction.leave_transaction_management()
In case of error in line 103 transaction block is finished and exception is raised again, but in line 111 this exception is cached and processing continues. If option show_traceback is turned off, it simply returns from the command in line 109 so it is ok then.
Example:
$ python manage.py loaddata backup.json --traceback Installing json fixture 'backup' from absolute path. Traceback (most recent call last): File "manage.py", line 21, in <module> execute_manager(settings) File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 272, in execute_manager utility.execute() File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 219, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 72, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 86, in execute output = self.handle(*args, **options) File "/usr/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 125, in handle transaction.leave_transaction_management() File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 67, in leave_transaction_management raise TransactionManagementError("This code isn't under transaction management") django.db.transaction.TransactionManagementError: This code isn't under transaction management
Attachments (1)
Change History (3)
by , 17 years ago
Attachment: | show_traceback.patch added |
---|
comment:1 by , 17 years ago
Has patch: | set |
---|
comment:2 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Added patch. To test it, create some buggy fixture (lets say empty file buggy.xml), and use commands:
python manage.py loaddata buggy.xml
python manage.py loaddata buggy.xml --traceback