Oleg Broytmann a écrit :
> On Fri, Jun 09, 2006 at 12:08:35PM +0200, sophana wrote:
>   
>>    def __setstate__(self,id):
>>        a=self.get(id)
>>        self.__dict__=a.__dict__
>>     
>
>    This breaks cache - "a" is now in the cache instead of self. See how
> .get() is implemented.
>
> Oleg.
>   
Yes there is a big problem
In my previous example:
 >>> a=Users.get(1)
 >>> import cPickle
 >>> b=cPickle.dumps(a)
 >>> c=cPickle.loads(b)
 >>> c
<Users 1 login='asdf' password='asdfasdf' email="'[EMAIL PROTECTED]'" 
validated=True validationString='0sdr8z6kfj'>
 >>> c.password='qwerqwer'
 >>> a
<Users 1 login='asdf' password='qwerqwer' email="'[EMAIL PROTECTED]'" 
validated=True validationString='0sdr8z6kfj'>

I did some more test:
 >>> Obj.get(2).owner is a
True
 >>> Obj.get(2).owner is c
False
 >>> a==c
False
 >>> a is c
False

Does someone has a suggestion?
unfortunately pickle API could have been better for __setstate__
if __setstate__ return something, pickle.load should return the returned 
object instead of self.


_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to