hey François -
are you using the SessionTransaction explicitly ? or connection.begin
() ? Ive tried many combinations, and the only way I can reproduce
the problem is by doing something incorrect:
c = engine.connect()
s = create_session(bind_to=c)
tran = c.begin()
session_tran = s.create_transaction()
s.save(User())
s.flush()
u = User()
s.save(u)
s.user_name = 'some user'
tran.commit()
session_tran.commit()
the reason the above is incorrect is because the Transaction and
SessionTransaction are not nested properly.
The fix you have wouldnt be correct since the SessionTransaction is
being closed (if not the underlying connection, which was the
original bug), so it should remove its association from its host
Session.
On Oct 20, 2006, at 6:59 AM, François Wautier wrote:
Hi Michael,
It seems I spoke too quickly.
The problem is now when I try to flush a second time with a new
object.
Something like this
newguy=dbPeople()
session.save(newguy)
newguy.Lastname=Doe
newguy.Firstname=John
newguy.gender=Ambiguous
session.flush()
newguy=dbPeople()
session.save(newguy)
newguy.Lastname=Doe
newguy.Firstname=Jane
newguy.gender=Sheila
session.flush()
The last session flush results in a new record being written to the
database,
but an exception is raised, with the error message
This transaction is inactive
If one were to try to add more dbPeople, the records won't be saved
into the
database for the session keeps on using the same key value (the
table uses
an auto_increment)
I hacked the code a bit and I solved the problem but I am far
from sure
that I did the right thing for all cases
In lib/sqlalchemy/orm/session.py around line 67 I changed
for t in self.connections.values():
if (t[2]):
t[0].close()
self.session.transaction = None
into
keeptransaction=False
for t in self.connections.values():
if (t[2]):
t[0].close()
else:
keeptransaction=True
if not keeptransaction=False:
self.session.transaction = None
I wonder if something like this would not be preferable (but I
again, I have
no clue as to what the consequences of my code is)
closeall=False
for t in self.connections.values():
if (t[2]):
closeall=True
if closeall:
for t in self.connections.values():
t[0].close()
self.session.transaction = None
Regards,
François
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~--~~~~--~~--~--~---