← Back to team overview

launchpad-dev team mailing list archive

Need some help to understand weirdness with the propertycache API

 

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.

I also can't replicate the problem without running the full test
suite.

To me this smells like:

- I don't fully understand how adapter registration works, especially
  in the context of Launchpad, or

- Some test machinery, or a layer, is doing ugly things to site
  managers and the failing tests are just unlucky enough to run
  afterward, or

- There's a bug in zope.interface and/or zope.component.

My inability to understand this problem makes me reluctant to use some
more interesting parts of Zope's component architecture, and revert to
writing boilerplate like:

  if IDistributionSourcePackage.providedBy(self):
      args['distribution'] = self.distribution
      args['sourcepackagename'] = self.sourcepackagename
  elif IProduct.providedBy(self):
      args['product'] = self
  elif IProjectGroup.providedBy(self):
      args['project'] = self
  elif IDistribution.providedBy(self):
      args['distribution'] = self
      args['sourcepackagename'] = None
  elif IMilestone.providedBy(self):
      args['milestone'] = self
  elif IProductSeries.providedBy(self):
      args['productseries'] = self
  elif IDistroSeries.providedBy(self):
      args['distroseries'] = self
  ...

Ad nauseam.

Can anyone save the world from this fate?

Cheers, Gavin.


[1] https://bugs.edge.launchpad.net/launchpad-foundations/+bug/628762



Follow ups