#10813: Database errors in the shell should roll back the transaction ------------------------------------------+--------------------------------- Reporter: Glenn | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: SVN Keywords: | Stage: Unreviewed Has_patch: 1 | ------------------------------------------+--------------------------------- If an SQL statement fails in Postgresql, the connection refuses to run any further SQL commands until the transaction is rolled back. In normal operation, this is fine; but in the shell, it's a constant aggrevation.
This is related to #852, but that ticket was asking to automatically rollback inside the connection itself, which isn't good. This ticket is only regarding the shell. If I run a function that causes an SQL error, the shell's connection should not be left in an unusable state, forcing me to manually import db.transaction and roll back a transaction I never asked for. The shell should catch DatabaseError and rollback before returning to the console. The attached patch implements this. I've only tested with Postgresql. This does not affect IPython (which I know nothing about). Before: {{{ >>> obj = User(name="Bill") >>> obj.save() ... IntegrityError: duplicate key value violates unique constraint "app_user_name_key" >>> obj.name = "Jim" >>> obj.save() ... InternalError: current transaction is aborted, commands ignored until end of transaction block }}} Now: {{{ >>> obj = User(name="Bill") >>> obj.save() ... IntegrityError: duplicate key value violates unique constraint "app_user_name_key" >>> obj.name = "Jim" >>> obj.save() >>> }}} -- Ticket URL: <http://code.djangoproject.com/ticket/10813> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---