[sqlalchemy] Re: Object is already attached to session

2008-06-13 Thread Gaetan de Menten

On Thu, Jun 12, 2008 at 4:58 PM, bollwyvl [EMAIL PROTECTED] wrote:

 I am running into similar problems, adding to the complexity the
 threadpool module.

 Here's a post that might help:
 http://blog.uxpython.com/blog/web/view/116

 I am still running into problems, however, based on parent/child
 relationships... i think the answer lies in the sqlalchemy `cascade`
 property, but I as yet have not found a way to modify that directly in
 the Elixir layer.

I'm not sure the cascade property is the answer to Matt's problem
but in any case, you can use the cascade argument on Elixir
relationships exactly as you do with SQLAlchemy's relation(). In fact
any argument not specifically used by Elixir's relationships is
forwarded to the relation() construct.

-- 
Gaƫtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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: Object is already attached to session

2008-06-12 Thread Michael Bayer


On Apr 16, 2008, at 3:55 PM, mg wrote:


 I have a couple of threads that are working on the same objects,
 passing them back and forth in queues. I have just started testing
 with the Sqlalchemy parts turned on, and I am getting the already
 attached to session message. Also of note is that I am using the
 Elixir declarative layer, although I don't think that is causing the
 problem. Here is a basic example of what I am doing.

 queue = Queue()

 class History(Entity):
status_id = Field(Integer)
text = Field(Text)
using_options(tablename='history', autosetup=True)
using_table_options(useexisting=True)

 class Worker(threading.Thread):
def run(self):
items = History.query.all()
for item in item:
queue.put(item)
for i in range(pool_size):
consumer = Consumer(self.getName())
consumer.start()

 class Consumer(threading.Thread):
def run(self):
item = queue.get_nowait()
if True:
item.status_id = 1
else:
item.status_id = 2
item.update()
item.flush()

 when I try to update I get: InvalidRequestError: Object
 '[EMAIL PROTECTED]' is already attached to session '21222960' (this is
 '21223440')

 any help would be greatly appreciated.

if you're passing objects between threads with corresponding  
contextual sessions, you need to be expunging those objects from the  
session in which they're present before using them in another  
session.  Use Session.expunge() for this.



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