Re: slooow delete

Sebastien Bigaret <[email protected]> Fri, 18 Mar 2005 19:00:53 +0100
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
John Lenton <[email protected]> wrote:
> Thank you very much for your reply. Just one small doubt
> remains:
>=20
>=20
> On Fri, 18 Mar 2005 12:18:57 +0100, Sebastien Bigaret
> <[email protected]> wrote:
> >=20
> > And, if you do this: just make sure that
> >=20
> > - either task.getMeal().isFault() =3D=3D true
> >=20
> > - or that, in case it is not, that
> >     task.getMeal().getTasks().isFault()=3D=3Dtrue
> >=20
> >   In this last case, if it is false, then you can do the
> >   meal.addToTasks(task) without any overhead, since this
> indicate
> > that
> >   the fetch has already be done.
>=20
> is there any case where the last line would return false,
> instead of
> raising an AttributeError?

Good question ;)  Here are the details

First situation: you have a newly created object ; in this case,
meal.getTasks() will be a real python list (actually a list or a
tuple), assigned by the constructor, and you'll get an
AttributeError.

Second situation: the object has been fetched by the framework.=20
In this case, any attribute corresponding to a tomany
relationship is initialized with the so-called <<to-many fault>>
object, responsible for lazily initializing the list when
appropriate.  If you're curious, you'll have a look at
FaultHandler.AccessArrayFaultHandler, which is the corresponding
class proxying the underlying list.  So, in this case, you'll
get a true or false answer when asking
meal.getTasks().isFault().

  As a conclusion, you're right, you have to check for
AttributeError as well and your code will handle all possible
situations.

-- S=E9bastien.


-- S=E9bastien.



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=3D6595&alloc_id=3D14396&op=3Dclick