On Wed, Feb 25, 2009 at 10:29 PM, Sushant Sinha <sushant...@gmail.com>wrote:
> > I am also facing the same problem. Here is the description of my > problem. The code tries to create a new user and emits an error when > an error happens: > > try: > user = auth.models.User.objects.create_user(uname, email, password > = passwd) > except db.IntegrityError: > htmldict['msg'] = 'Username "%s" has already been taken. Try a > different one.' % uname > return render_to_response('register.html', htmldict) > > Now this gives the error: > > Traceback (most recent call last): > > [snip] > File "/usr/lib64/python2.5/site-packages/django/db/models/sql/ > query.py", line 1700, in execute_sql > cursor.execute(sql, params) > > InternalError: current transaction is aborted, commands ignored until > end of transaction block > > I did not know that the template rendering also uses the database > cursor. So I am catching the exception but I why should I care about > the cursor. The django model does not expose cursor by default and > that should be used only when I am writing custom SQL queries. > You want to use the transaction commit/rollback routines, not cursor ones: http://docs.djangoproject.com/en/dev/topics/db/transactions/ > > I think that the cursor should rollback if there is an error and then > throw the exception. Thats a more reasonable behavior than what we > have right now. > Except rollback isn't the only option, from what I read. Though I have never experimented with it, apparently your code could also choose to commit the transaction at this point. Your code is the only code with enough context to know whether what's been done so far should be committed anyway despite the error or if the error should cause the whole thing to be rolled back. 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 -~----------~----~----~----~------~----~------~--~---