[ZODB-Dev] know the state of an object
dvd
dvd at gnx.it
Fri Oct 14 10:36:36 EDT 2005
On Thu, 2005-10-13 at 19:04 -0400, Tim Peters wrote:
> > from the connection object,
>
> You didn't say which version of ZODB you're using. Since you believe
a
> Connection keeps track of which objects have been modified, I'll
assume
> you're using ZODB 3.3 or later (which is either true, or your belief
about
> who keeps track of modified objects is false ;-)).
yup i missed this info, i'm using zodb 3.4
>
> > so i overload the __setattr__ method in my base-class and keep track
> > of the modified objects
> >
> > But that's the problem, __setattr__ is called also when ZODB loads
the
> > objects from the storage and reconstructs it, so is there a way to
know
> > the state of the object (unpickilng, modified, clean etc etc)?
>
> The good news is that obj._p_state reveals the current state of a
persistent
> object. The possible values are exposed by the `persistent` module:
I see, yesterday, after my message obviously, i see the light and write
this code
class PersistentObject(Persistent):
[... some code ...]
def __setattr__(self, attr, value):
if not self._p_setattr(attr, value):
super(PersistentObject, self).__setattr__(attr, value)
if not attr.startswith('_p_') and self._p_changed and attr!
='_Modified':
self.Touch()
> So, in the end, I don't see any hope for you via this route, short of
this:
> register an object as changed in your __setattr__ without worrying at
all
> about _why_ __setattr__ was called. Later, when you "do something"
with
> your list of modified objects, simply ignore any whose state at that
time is
> UPTODATE. Those are exactly the objects whose state got materialized
but
> didn't change thereafter.
Ok, thank you for your help
bye
More information about the ZODB-Dev
mailing list