On Aug 25, 2008, at 12:24 AM, Harish K Vishwanath wrote:
>
>
> The line USERIDLIST.append(user.UserID),is trying to append the
> newly added (to the database) user object's primary key (UserID)
> into a List in one thread , to be used by another thread which tries
> to modify the object. Its throwing up exceptions there.
>
> This error will go away if I set expire_on_commit = False.
From all indications, this is concurrent Session access which is not
supported - any object which is associated with a Session can call
upon its owning Session at any time.
Sharing the object across threads works against the transaction model
which you are trying to take advantage of. Your second thread is in
its own transaction, and should be loading all of its information from
that transaction. By hitting user.UserID in the second thread, you're
attempting to access database data from the original transaction which
"user" is still associated with and concurrency related issues are
occuring.
Approaches to fix include:
1. The easiest way to do this is to keep all objects local to one
thread.
2. Instead of passing "user" to the other thread, pass only
user.UserID to the other thread. This keeps the access to "user"
within its owning thread.
3. expunge() your User object from the thread in which it was
created, and add() it to the Session corresponding to the other
thread, before accessing user.UserID
4. merge() your User object to the Session corresponding to the other
thread, where a copy of it will be created local to that Session
(would have to see if merge() is smart enough to not load in expired
attributes, though).
5. use mutexing to prevent concurrent access to the first Session
(this may also necessitate not using ScopedSession depending on usage
patterns).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---