Ticket #2290 (closed defect: fixed)

Opened 9 years ago

Last modified 9 years ago

Provide helper to fight against acquisition insanity in Five

Reported by: gracinet Owned by: gracinet
Priority: P2 Milestone: CPS 3.5.3
Component: CPSonFive Version: 3.5.1
Severity: normal Keywords:
Cc:

Description

The problem is that Five's BrowserView? inherits from Acquisiton.Explicit, which is probably quite needed in a Zope 2 context. Therefore, almost anything set as attribute on the class is returned in an acquisition wrapper, and set in the context of the view itself.

Here's an  explanation on the z3-five mailing list.

This becomes insane if one needs to set an object that already has acquisition context on the view. Some core Zope methods, such as getPhysicalPath won't work because the object has lost its natural Even worse, trying to unwrap with aq_inner does not solve the problem.

Simplest example demonstrating this for a view class view:

  >>> view.context2 = view.context
  >>> view.context2.absolute_url_path()
  AttributeError: getPhysicalPath
  >>> view.context.absolute_url_path()
  '/my_context'

No matter the amount of aq_inner one could imagine to insert in there does anything improving the situation. Note that for objects with reasonible lookup time, this is not so big a problem, once one has been warned.

In order to avoid repeating the same workarounds over and over, and to ensure easy upgrade with later versions of Five or ZTK, we have to provide an helper to circumvent this insanity.

It's not hard to deduce from the above cited mailing-list post, but can't apparently be made really transparent from python code.

Change History

comment:1 Changed 9 years ago by gracinet

The funny thing in the example above is that context is itself an instance of ImplicitAcquirerWrapper that's less broken for some magical reason.

comment:2 Changed 9 years ago by gracinet

  • Component changed from CPS (global) to CPSonFive

comment:3 Changed 9 years ago by gracinet

  • Status changed from new to closed
  • Resolution set to fixed

Done and pushed (got me the honour to write the first tests for CPSonFive). Every attempt to fiddle with ___getattr___ or __getattribute___ failed so far. The former because it's completely bypassed once the view is intantiated. The second breaks the lookup.

Therefore, there's a distinct API, provided by

from Products.CPSonFive.browser import AqSafeBrowserView

Namely: aqSafeGet(), aqSafeSet() and aqSafeDel(). Check the tests for more details.

This is not really satisfactory, but it works.

Note: See TracTickets for help on using tickets.