- attached sqlalchemybug.py
Strange "objectdeletederror" when transferring instance between transactional sessions
On SQLAlchemy-0.5.7-py2.6.egg, with MYSQL databases (sqllite has no problems): - I begin two transactional sessions (no autocommit) - I create and commit an instance via the first one - I close the first session (the instance is now detached) - I add the instance to the second session
Then the instance is actually NOT properly added to the second session, trying to access its attributes raises misc. errors like "objectdeteletederror" or "not in persistent state".
Note that the problem doesn't apear if I only create the second session after closing the first one, or if I don't "initialize" its transaction by issuing a query on it before adding the instance.
Comments (3)
-
Account Deleted -
repo owner - changed status to wontfix
this is a simple effect of transaction isolation. MySQL's docs on this are here:
http://dev.mysql.com/doc/refman/5.1/en/innodb-transaction-model.html
basically Session2 has already begun a transaction and has read all rows of the table. Changes to this table will not be visible until it begins a new transaction. You can see the effect as follows:
session2.rollback() # transfer to session 2 session2.add(a) # works ! print a.ssi_acronym
-
Account Deleted Allright, I hadn't noticed that "transient" and "detached" instances were so different... actually a transient instance is like a normal python object, containing its full information, whereas a detached object is like a pointer to DB fields, needing a functional session to retrieve its attributes...
I guess I get it now, thanks.
- Log in to comment
reproduces the "broken adding of instance to session" with mysql