Ticket #10813: django-roll-back-after-db-error.diff

File django-roll-back-after-db-error.diff, 1.1 KB (added by Glenn, 6 years ago)
  • django/core/management/commands/shell.py

     
    5656                        pass
    5757                # This will import .pythonrc.py as a side-effect
    5858                import user
    59             code.interact(local=imported_objects)
     59
     60            class DjangoConsole(code.InteractiveConsole):
     61                def showtraceback(self):
     62                        import sys
     63                        from django.db import connection, DatabaseError
     64
     65                        code.InteractiveConsole.showtraceback(self)
     66
     67                        # Rollback after a DatabaseError, so the shell doesn't get stuck in "current
     68                        # transaction is aborted" in Postgresql.
     69                        exc_type, exc_value, tb = sys.exc_info()
     70                        if isinstance(exc_value, DatabaseError):
     71                            connection._rollback()
     72
     73            interp = DjangoConsole(imported_objects)
     74            interp.interact()
     75
Back to Top