Re: [Modeling-users] toOne relationship returns base class instead of subcl
Status: Abandoned
Brought to you by:
sbigaret
|
From: John L. <jl...@gm...> - 2004-07-23 16:48:22
|
On 23 Jul 2004 15:02:00 +0200, Sebastien Bigaret
<sbi...@us...> wrote:
>
>
> Now you'll see that the discussion "ended" there with an open
> question, about if and how this could/should be changed. Time to
> rediscuss this I guess, huh?
ok, I've got no self-control, and I read the post. I then added the
following __getattr__ to CustomObject---I'm not at all certain this is
where it belongs, but it worked for me :) Not in production, and not
tested, but I thought I'd post it anyway
It does some magic with sys._getframe to ensure it's not called
recursively; it does it after checking the attribute doesn't start
with an underscore---which I'm not certain is ok.
def __getattr__(self, attr):
if attr.startswith('_'):
raise AttributeError
f = sys._getframe()
if f.f_code is f.f_back.f_code:
raise AttributeError
print >> sys.stderr, "*** faulting object %s: %s called" % (self, attr)
self.willRead()
return getattr(self, attr)
if this is the kind of thing we're talking about, I see no problem
with it---the default behaviour is preserved due to the raising of
AttributeErrors, and it's not *too* expensive. The _getframe magick
isn't essential, but it helps.
This still didn't fix the other issue, however...
--
John Lenton (jl...@gm...) -- Random fortune:
bash: fortune: command not found
|