← Back to team overview

launchpad-dev team mailing list archive

Re: Need some help to understand weirdness with the propertycache API

 

On Fri, 10 Sep 2010 12:41:12 +0100, Gavin Panella <gavin.panella@xxxxxxxxxxxxx> wrote:
> Hi,
> 
> Recently I landed the new propertycache API, which is a replacement
> for the cachedproperty API (there is still a cachedproperty decorator,
> but it lives in the propertycache module rather than cachedproperty).
> 
> It uses adaption to get the cache object for the target:
> 
>   cache = IPropertyCache(target)
>   cache.a_cached_value = 1234
> 
> However, I had to hobble it at the last minute to only pretend to do
> adaption (i.e. IPropertyCache is currently a plain function, not an
> interface) because the adapters were not registered in several tests,
> and so cached properties were breaking. See bug 628762 [1] for the
> lowdown.
>
> The adapters are registered via ZCML *and* with the global site
> manager, so I have no idea why they are sometimes not present.
> 
> It already seems weird to register them both via ZCML and the global
> site manager. If I just use ZCML a whole raft of tests fail. If I just
> use ZCML a different raft of tests fails.

This may not be news to anyone, but as far as I can see hasn't been
mentioned explicitly: the adaptor registrations in the ZCML take effect
when you (a) set up the FunctionalLayer (b) call
execute_zcml_for_scripts() (c) during appserver startup somehow.  So if
you only put the registrations in the ZCML and then run tests that use
cachedproperty but aren't in any layer -- and I bet we do this a bit --
they will blow up.

AIUI, setting up the FunctionalLayer *replaces* the global site manager,
so if you just do the registration at import time, any tests that use
cachedproperty inside the FunctionalLayer -- and there are certainly a
lot of these! -- will fail.

If you do both, I don't know offhand why some tests would still fail.
Maybe some tests have overzealous tearDowns that rip out all adapter
registrations.

But I would say this: do adapter registrations in ZCML.  If you want to
use adaptation in cachedproperty, this means all tests using
cachedproperty need to be in the FunctionalLayer.  If this is too
onerous, then don't use adaptation in cachedproperty.

HTH,
mwh



Follow ups

References