Hi all,

I really like the idea of the with statement thats coming in Python
2.6 and want to use it in my SQLAlchemy code. However I can't seem to
get it to work for commits. I have tried the below code (snipped):

Session = sessionmaker(bind=engine)

def loadData(filename):
    sess = Session()
    with sess.begin():
        reader = csv.reader(open(filename))
        for ept in reader:
            p = Spam(ept[0], ept[10], ept[12], ept[13],
float(ept[14]), ept[5], int(ept[8]) )
            sess.save(p)
        #sess.commit()

However this doesnt commit the Spam objects I create. So if I
uncomment the sess.commit() line, I get an AttributeException:

AttributeError: 'NoneType' object has no attribute 'transaction', but
I thought the default for sessionmaker was to use autocommit=True?

What am I doing wrong with this code?

I am also wondering if there is a way to force a commit of the code
after a certain number of objects are saved to a session (added to the
map), like forcing a commit after a 20 objects are added, since I want
to try to keep balance my memory usage and the number of commits I
make.

Many thanks in advance

Nathan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to