I'm guessing the first exception is actually your non-unique email 
address failing the uniqueness check.  The message you show below makes 
clear what is wrong: the entire loop is inside a single transaction, and 
once the database has failed an update, it marks the entire transaction 
as aborted, and refuses to do anything else.  Your python loop continues 
on as it should, but all further database operations are no-ops, so the 
result in the database is just as if you had exited the loop.

You have a few options:
1) make your transaction more fine-grained so that each iteration of the 
loop is a new transaction, limiting the damage when an update fails,
2) clean your data before entering the loop so there won't be a 
uniqueness violation,
3) write a Python check against the uniqueness so that you won't attempt 
an update that would fail.

--Ned.

Greg wrote:
> Norman,
> I added those print statements and ran the script.  The output was
> this over and over again:
>
> ///
>
> current transaction is aborted, commands ignored until end of
> transaction block
>
> //
>
> Any suggestions?
>
> On May 20, 3:24 pm, "Norman Harman" <[EMAIL PROTECTED]> wrote:
>   
>> Greg wrote:
>>     
>>> Since we know what the exception is.  The email address already exist
>>> in the db (I have unique=True for the email field).  I thought that
>>> having 'except: pass' would solve that problem.  However, do I need to
>>> catch a certain exception in order for my loop to continue.  Because
>>> as of now when the exception happens my loop stops.
>>>       
>> You don't *know* that is what the exception is, you assume that.  This
>> is one reason it is bad to catch all exceptions.  You don't know what
>> you are getting.
>>
>> The loop, as written, will continue.  There is something else going on.
>>
>> I would add print statements to determine what is in fact happening.
>>
>> for row in reader:
>>       try:
>>           b = OrderEmail(name=row[0], email=row[1], been_sent="0")
>>           b.save()
>>           print "saved", row
>>       except Exception, msg:
>>           print msg
>>
>> --
>> Norman J. Harman Jr.  512 912-5939
>> Technology Solutions Group, Austin American-Statesman
>> ___________________________________________________________________________
>> Get out and about this spring with the Statesman! In print and online,
>> the Statesman has the area's Best Bets and recreation events.
>> Pick up your copy today or go to statesman.com 24/7.
>>     
> >
>
>   

-- 
Ned Batchelder, http://nedbatchelder.com


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to