On 5/21/06, Koen Bok <[EMAIL PROTECTED]> wrote:
I'd like to do something really simple. I have an order with some
products related to it. When I set the quantity of a product to 0,
I'd like it to destroy itself.
The property quantity is bound to the quantity table column by a mapper.
But when I do product.quantity = 123, _set_quantity does not get
called. What am I doing wrong? Using 0.2 latest SVN.
class Product(object):
def _set_quantity(self, quantity):
print "I GOT CALLED!"
self.quantity = quantity
The above line, if _set_quantity() were getting called, would trigger
an infinite loop. You're trying to set "self.quantity" -- which will
call your _set_quantity() property again, which will try to set
"self.quantity", which will call _set_quantity() again, and so on.
For the *actual* quantity value, you probably want to use a name like
"self._quantity" instead.
def _get_quantity(self, quantity):
return self.quantity
And, of course, use the same name here.
quantity = property(_get_quantity, _set_quantity)
What does your SQLAlchemy mapper look like? Have you told it about
your class's property, as per
http://www.sqlalchemy.org/docs/datamapping.myt#data_synopsis_overriding?
If you haven't, that's the most likely cause of your bug: the
SQLAlchemy is overriding the "quantity" attribute of your class and
hiding the property you created.
Those are the two possible problems I can see. If you fix those and
_set_quantity() is still not getting called, let us know.
--
Robin Munn
[EMAIL PROTECTED]
GPG key 0xD6497014
Rȧ�:&q�[���y�hv����^y�h��i��py����z�r���!���n}�h�ꮉ�%����ފ{^���y�^r薈2����쨺��m欉�ã
塧HŞm*az����bq�b�t�����]5m�v����!xg��x��m���zV���ږF�����\�