Practically all persistent languages impose some restrictions on
programming style, warning against constructs they can't handle or
adding subtle semantic changes, and the ZODB is no exception.
Happily, the ZODB's restrictions are fairly simple to understand, and
in practice it isn't too painful to work around them.
The summary of rules is as follows:
- If you modify a mutable object that's the value of an object's
attribute, the ZODB can't catch that, and won't mark the object as
dirty.
The solution is to either set the dirty bit yourself when you modify
mutable objects, or use a wrapper for Python's lists and dictionaries
(PersistentList,
PersistentMapping)
that will set the dirty bit properly.
- Certain of Python's special methods don't work when they're
defined on ExtensionClasses. The most important ones are the
__cmp__ method, and the reversed versions of binary
arithmetic operations: __radd__, __rsub__, and so
forth.
- Python's built-in isinstance() and issubclass()
functions don't work properly on ExtensionClasses. Solution: use
custom isinstance() and issubclass() functions
that handle ExtensionClasses correctly.
- Recent versions of the ZODB allow writing a class with
__setattr__ , __getattr__, or __delattr__ methods. (Older versions didn't support this at all.)
If you write such a __setattr__ or __delattr__ method,
its code has to set the dirty bit manually,
Let's look at each of these rules in detail.
Subsections