[ZODB-Dev] Re: false write conflicts

Marius Gedminas mgedmin at b4net.lt
Tue Mar 2 12:01:43 EST 2004


On Tue, Mar 02, 2004 at 11:15:42AM -0500, John Belmonte wrote:
> That is arguably a Python wart.  With regard to the containing object, 
> it seems unfortunate to consider "foo.bar +=1" different than 
> "foo.bar[a] = b".
> 
> This wrapper for Persistent.__setattr__ looks like it will suit my needs:
> 
>   class MyPersistent(Persistent):
>     def __setattr__(self, key, val):
>       if not (self.__dict__.has_key(key) and self.__dict__[key] is val):
>         Persistent.__setattr__(self, key, val)

I've seen a recommendation somewhere that it is better to write

  self.attr[x] = y
  self.attr = self.attr      # notify Persistence that something changed

than

  self.attr[x] = y
  self._p_changed = True     # notify Persistence that something changed

Your wrapper would hide the assignment in the first snippet from Persistence,
negating its purpose.

Marius Gedminas
-- 
If nothing else helps, read the documentation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20040302/7f2ce6ea/attachment.bin


More information about the ZODB-Dev mailing list