Daer all

I have a following problem :

Session = sessionmaker(bind=engine)

session = Session()
for item in items:
    item1 = session.query(item)
    if len(item1)==0:
        session.add(item1)
        session.commit()

The session is valid for a loop and I write items in a database during
each iteration. Can it happen that if an item is identical to the
previous one, the session.commit() will not make it to write the
previous item in the database before the query of the next iteration
is executed and the next session.commit() will fail because of
sqlalchemy.exc.IntegrityError: (IntegrityError) duplicate key value
violates unique constraint.
How can I make sure that the previous item is already in the database
before the query in the next iteration is carried out?
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to