On Fri, Jun 26, 2009 at 12:59 AM, sico <allensi...@gmail.com> wrote: > > Hi > > Is it possible to rollback the transaction without raising an > exception when the transactions are tied to http requests?? > I'm writing several records in one post call, if any fail I'd like to > rollback the transaction but return a nice error message to the user. > Surely I'm missing something as this seems quite a simple > requirement... >
You haven't given any indication of what you had tried here. Since you are asking the question I gather whatever you have tried hasn't worked, but I'm not sure where you are running into trouble since I don't know what you've done. First, if you want to be able to roll back some already-completed operations due to a subsequent one failing, you will need to use something other than Django's default autocommit behavior, as described here: http://docs.djangoproject.com/en/dev/topics/db/transactions/#topics-db-transactions The commit_manually decorator is probably what you want to use. Second, if you want to recover from attempting something that causes a database error, your code needs to catch whatever database exception is raised and recover. Something like: try: instance = new_model.save() except IntegrityError: transaction.rollback() ... whatever else you want to do to inform the user ... Your code must be prepared to handle the possible database errors, there is no setting to tell the framework to auomagically eat them and rollback the transaction (if it did, how would you know that had happened?). Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---