[sqlalchemy] Re: Query Threading Issue

2008-05-06 Thread Michael Bayer


On May 4, 2008, at 10:59 AM, Paul Johnston wrote:

 Hi,

 I'm writing a ToscaWidget to do a kind of data grid. The way I've  
 designed it so far, you pass an SA query object to the Widget when  
 it's created. Then, each time it's displayed, it applies a few extra  
 filters to the query and fetches the results. I'm using scoped  
 sessions, and the query ends up being used in several different  
 threads.

 My initial thoughts are that there could be thread safety problems  
 with this approach, although in practice it works just fine. How bad  
 are the threading issues? And is there anything I can do to fix it,  
 e.g. a step that clones a query and attaches it to the session for  
 the current thread?


ive thought about this, and the Query is not in fact tied very hard to  
a partcular Session (or at all).  I think it would be workable for us  
to add a using_session() method to it, i.e.:

q = Query(User)

print q.using_session(somesession).all()

I sort of thought we had already done this at some point, or proposed  
it, and I'm not sure why it didn't actually happen.



--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Query Threading Issue

2008-05-06 Thread Paul Johnston

Hi Mike,

ive thought about this, and the Query is not in fact tied very hard to  
a partcular Session (or at all).  I think it would be workable for us  
to add a using_session() method to it, i.e.:
  

The original workaround you suggested of using a callable works fine for 
now. A using_session method would be nice, avoid exposing this detail to 
the user of my widget. Although pretty soon after I made the change I 
found a separate advantage of using a callable, so I'll probably stay 
with that. I guess another option is to make the query bind to the 
scoped_session object, so it picks up an appropriate session when it 
actually uses it.

Thanks for taking a look,

Paul

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Query Threading Issue

2008-05-04 Thread Michael Bayer


On May 4, 2008, at 10:59 AM, Paul Johnston wrote:

 Hi,

 I'm writing a ToscaWidget to do a kind of data grid. The way I've  
 designed it so far, you pass an SA query object to the Widget when  
 it's created. Then, each time it's displayed, it applies a few extra  
 filters to the query and fetches the results. I'm using scoped  
 sessions, and the query ends up being used in several different  
 threads.

 My initial thoughts are that there could be thread safety problems  
 with this approach, although in practice it works just fine. How bad  
 are the threading issues? And is there anything I can do to fix it,  
 e.g. a step that clones a query and attaches it to the session for  
 the current thread?


a Query is normally bound to a single Session (and in 0.5, it is  
always bound as such, the get_session() method is removed) so that  
approach would present lots of threading issues.  A better approach  
would be to maintain a reference to a callable which produces the  
Query object you need upon demand.

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---