Opened 12 years ago

Closed 11 years ago

#6420 closed (fixed)

Option show_traceback in causes problems with transactions on exceptions

Reported by: Grzegorz Lukasik <hauserx@…> Owned by: nobody
Component: Core (Other) Version: master
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


Option show_traceback in loaddata does not work properly - instead of correct traceback TransactionManagementError is displayed.

Option show_traceback was introduced in this commit:

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                           "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.


$ python loaddata backup.json --traceback
Installing json fixture 'backup' from absolute path.
Traceback (most recent call last):
  File "", line 21, in <module>
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 272, in execute_manager
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 219, in execute
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 72, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 86, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.5/site-packages/django/core/management/commands/", line 125, in handle
  File "/usr/lib/python2.5/site-packages/django/db/", 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)

show_traceback.patch (1.1 KB) - added by Grzegorz Lukasik <hauserx@…> 12 years ago.

Download all attachments as: .zip

Change History (3)

Changed 12 years ago by Grzegorz Lukasik <hauserx@…>

Attachment: show_traceback.patch added

comment:1 Changed 12 years ago by Grzegorz Lukasik <hauserx@…>

Has patch: set

Added patch. To test it, create some buggy fixture (lets say empty file buggy.xml), and use commands:

python loaddata buggy.xml
python loaddata buggy.xml --traceback

comment:2 Changed 11 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [7199]) Fixed #6420 -- Corrected the handling of the --traceback option in loaddata. Thanks, Grzegorz Lukasik <hauserx@…>.

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