> You'll need to override ``__new__``. That's your hook. It's called
> when the database instantiates the object. Note that this is always
> true for Python. The ``__new__`` method is always called before an
> object is instantiated.

Actually, this doesn't seem to be what I want. ``__new__`` is called
*before* any attributes are set on the instance... so it's too early
to tell whether the instance is missing the attribute, as it certainly
will (since it's missing any attributes).

Is there any hook to call *after* the instance attributes get set/loaded
from the database?

Here is my code that didn't work, in case I'm just doing something silly:

class Line(Persistent):
    def __new__(cls, *args, **kwargs):
        inst = super(Line, cls).__new__(cls, *args, **kwargs)

            inst.id     #every instance in the DB already has an 'id'
        except AttributeError:
            return inst
        print 'we are here...' #this is never printed

            inst.expired  #the thing i actually want to guarantee
        except AttributeError:
            inst.expired = False

        return inst

- Claudiu
For more information about ZODB, see http://zodb.org/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to