ZODB.Persistent Objects.Persistent
Documentation
Persistent is a mix-in class for �persistent� objects. It may not be possible to instantiate Persistent directly.
Persistent objects have the following important features:
- Each persistent object gets its own database record (or records, if there are multiple revisions),
- A persistent object automatically interacts with the rest of the persistence system to assure that the database is updates when the object�s (persistent) state changes.
Instance dictionary
Accessing data in an object's instance dictionary through it's __dict__ attribute bypasses the persistence mechanisms. This is by design and is sometimes, but rarely, useful.
Never
Implement the special Python methods __getattr__ or __setattr__.
These are already used by the persistence system. While it is possible to overide these correctly, it is extremely difficult.
Reserved
All attribute names beginning with �_p_� are reserved and attributes with names beginning with �_p_�, other than _p_changed, should not be assigned by application code.
Subobjects
Subobjects of persistent objects must be:
- Persistent,
- immutable, or
- used immutably
Here's an example of using a mutable object immutably:
def add(self, v):
data=self.data
data.append(v)
self.data=data
If the above rules are not followed, then special care must
be taken to register object changes when mutable sub-objects are
changed, as in:
def add(self, v):
self.data.append(v)
self._p_changed=1
Volatile
Attributes that should not be included in persistent state should have names beginning with '_v_'. See the __getstate__ method.