On Apr 11, 2007, at 11:45 AM, Arun Kumar PG wrote:

> Hi Guys,
>
> I am having two layers in my application: Manager and DAO.
>
> DAO deals with ORM and manager simply calls method on DAO.
>
> This is what I am doing in manager
>
> manager:
>   rs = dao.getResults (params)
>   obj = rs[0]
>   some logic.....
>   obj.name = 'some name'
>   dao.Update(obj)
>
>
> The getResults() in DAOis implemented like this:
>
> def getResults(params):
>   s = create_session()
>   rs = s.query(....)
>   return rs
>
> def Update(obj)
>   s = create_session()
>   s.update(obj)
>   s.flush()
>
> As per the sqlalchemy documentation, we should explicitly expunge()  
> the object and then use it with different session. The above logic  
> works fine even when the object gettting updated actually belongs  
> to the session that was created in the getResults() call.
>
> When I do the same on Python interactive interpreter prompt  
> *without having the above methods* it throws:
>
> raise exceptions.InvalidRequestError("Object '%s' is already  
> attached to session '%s' (this is '%s')" % (repr(obj), old, id(self)))
>

most likely that the session created in getResults() is falling out  
of scope in your application, therefore the entity is no longer  
"attached" to it (the operation thats throwing that error looks at a  
session_id attached to the object, looks in a WeakValueDictionary for  
that key to get the session).  variable scope is more sticky in the  
python interpreter.




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

Reply via email to