Just when I thought I understood the Session object, I found this
behavior:
( I am starting to think about concurrency and locking )

I create 2 sessions, and load each with the same ( persisted ) object.
The objects appear to be independent, even after both sessions have
flushed,
but when I commit one session, it suddenly picks up the change from
the other session!

This is confusing me!
What is going on here?
( my business object is a "Policy", and column "test" is not the PK )


class PolicyNotFoundException(Exception):
    pass

def open_policy(key):
    session = Session()
    try:
        policy = session.query(Policy).filter_by(key=key).all()[0]
        return policy, session
    except:
        raise PolicyNotFoundException

def test_concurrent_updates():
    policy1,session1 = open_policy('NICK')
    policy2,session2 = open_policy('NICK') # retrieves on pk...gets
same record
    assert( policy1 != policy2 )
    assert( session1 != session2 )
    assert( policy1 in session1 )
    assert( policy1 not in session2 )
    assert( policy2 in session2 )
    assert( policy2 not in session1 )

    policy1.test = 'ONE'
    session1.flush()

    policy2.test = 'TWO'
    session2.flush()

    assert( policy1.test == 'ONE' ) # not affected by flush of session
2

    session1.commit()
    assert( policy1.test == 'TWO' ) #  really?

-- 
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