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