Yes.  I saw that in the implementation of django.db.transaction.rollback().
I hesitate to use "private" methods, but since it's an odd requirement, I
may well go this way.

Thanks,
Bill

On Wed, Apr 14, 2010 at 7:25 PM, Joe <joesacco...@gmail.com> wrote:
> On Apr 14, 6:15 pm, Bill Freeman <ke1g...@gmail.com> wrote:
>> I'm running code from the manage.py shell to load stuff (from an XML export 
>> from
>> an excel read of a SQL Server dump, of all things), which gets a database 
>> error
>> (Postgersql correctly noticing that a value is too long for a field,
>> for instance) upon
>> calling the save method of a model.  I'd like to catch the exception, log 
>> about
>> what instance failed, and continue.
>>
>> But now the db connection is within a transaction, which I assume needs to be
>> rolled back, and the connection won't talk to me until I do so.
>>
>> The trouble is, I don't know how.  Just calling 
>> django.db.transaction.rollback()
>> doesn't work, and neither do several other guesses.
>>
>> I presume that the view decorators won't do it since this isn't a request
>> coming through the middleware to a view function.
>
> I found this ticket useful for an example of handling DatabaseErrors
> in the shell:
> http://code.djangoproject.com/ticket/10813
>
> Maybe try something like the following?
>
> from django.db import connection, DatabaseError
> try:
>    pass # your code that will throw the error
> except DatabaseError:
>    connection._rollback()
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to