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

Can anyone help here.

- A

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