I'm having an issue where a list of user-defined objects is disappearing as 
a function goes out of scope.  The list is stored in a PickleType column, 
and as that type does not track changes in the objects of the list, I am 
(knowingly, inefficiently) forcing the column to become dirty by setting 
the corresponding Python object to an empty list, and then to the new list 
value.  This is Python 2.7.3 with SQLAlchemy 0.9.8.  The session I'm using 
in the following code is created from a sessionmaker with default values 
aside form *expire_on_commit*, which is False.

The declaration of the class containing the list is simplified to the 
following:

class Target:
    __tablename__ = 'targets'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode)
    targetList = Column(PickleType, default=[])


def run(dbSession):
    targetInstance = makeTI(dbSession)#adds instance to session, flushes
    modifyList(targetInstance, dbSession, data)#blinks list values, dirties 
object in session.  Flushes changes, and all list contents are still 
subsequently present
    assert not any(dbSession.dirty)#assert passes
    assert not dbSession.is_modified(targetInstance)#assert passes
    print 'targetInstance list contents after init: ' + 
str(targetInstance.targetList)#prints list contents as expected
    #last place list contents are present. Upon return of run(), list will 
be empty again
    return

After flow of control returns to the caller of run(), a commit is done, 
then targetInstance is queried from the session, and the list is empty.  
Even if the list is accessed, or explicitly refreshed from the session, the 
list is empty.  How is that possible if the once-dirty session was flushed?

I know that there is optional in-place mutation tracking, but that's not 
being used here.
The relevant links are the official 
<http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/mutable.html> mutable 
docs, an extended conversation 
<https://bitbucket.org/zzzeek/sqlalchemy/issue/2994/pickletype-gets-not-updated-in-database-in>
 
with Mike on BitBucket.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to