I'm trying to refactor an existing cherypy/pyamf application and am running
into the following problem.  The code:

@RemoteClass(alias="common.model.vo.OrderVO")
class OrderVO(object): pass

class Orders(Service):
    """ Query and modify model.application.Order """

    klass = model.Order

    @secure()
    @toAmfType
    def save(self, orderVO):
        session = model.Session()
        order = session.query(model.Order).get(orderVO.order_id)
        if order is None:
            order = model.Order()
        order.ro_number = orderVO.ro_number
        order.customer_id = orderVO.cust_id
        order.notes = orderVO.notes
        order.tax_rate = self.app.location.tax_rate
        order.location_id = self.app.location.id
        session.add(order)
        session.commit()

        try:
            print order.id
        except:
            import traceback
            traceback.print_exc()

        return orderVO

Produces the following error (when I try to access the order instance after
the commit):

Traceback (most recent call last):
  File "mtzauto/services/order.py", line 46, in save
    print order.id
  File
"/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/attributes.py",
line 158, in __get__
    return self.impl.get(instance_state(instance), instance_dict(instance))
  File
"/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/attributes.py",
line 377, in get
    value = callable_()
  File
"/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/state.py",
line 185, in __call__
    attr.impl.key in unmodified
  File
"/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/mapper.py",
line 1883, in _load_scalar_attributes
    raise exc.ObjectDeletedError("Instance '%s' has been deleted." %
state_str(state))
ObjectDeletedError: Instance '<Order at 0xa51466c>' has been deleted.

What I'm trying to do is add or update a Order record from the orderVO
instance (sent from flex) and then update and return the orderVO instance
with the values returned after the commit (i.e. the id and default values
for new records etc).

I am using Python 2.6.4 and have tried both sqlalchemy 0.6 and 0.5.8.  The
Session() function was created with::Session =
scoped_session(sessionmaker()) and doctests for the class work -- it fails
only when running with cherrypy -- so I'm assuming it has something to do
with threading.

I've spent several hours trying to resolve this,  can anyone offer any
suggestions?


Thanks in advance,

Shawn

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

Reply via email to