<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You'll need to override ``__new__``. That's your hook. It's called<br>
when the database instantiates the object. Note that this is always<br>
true for Python. The ``__new__`` method is always called before an<br>
object is instantiated.<br></blockquote><div><br></div><div>Actually, this doesn't seem to be what I want. ``__new__`` is called</div><div>*before* any attributes are set on the instance... so it's too early</div>
<div>to tell whether the instance is missing the attribute, as it certainly</div><div>will (since it's missing any attributes).</div><div><br></div><div>Is there any hook to call *after* the instance attributes get set/loaded</div>
<div>from the database? </div><div><br></div><div>Here is my code that didn't work, in case I'm just doing something silly:</div><div><br></div><div><div>class Line(Persistent):</div><div> def __new__(cls, *args, **kwargs):</div>
<div> inst = super(Line, cls).__new__(cls, *args, **kwargs)</div><div> </div><div> try:</div><div> <a href="http://inst.id">inst.id</a> #every instance in the DB already has an 'id'</div>
<div> except AttributeError:</div><div> return inst</div><div> print 'we are here...' #this is never printed</div><div><br></div><div> try:</div><div> inst.expired #the thing i actually want to guarantee</div>
<div> except AttributeError:</div><div> inst.expired = False</div><div> </div><div> return inst</div></div><div><br></div><div>Thanks,</div><div>- Claudiu</div></div>