[Zope-CMF] Re: Accessing the "context"

Tres Seaver tseaver at palladion.com
Tue Oct 30 13:36:49 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wichert Akkerman wrote:
> Previously Charlie Clark wrote:
>> Am 30.10.2007 um 17:40 schrieb Wichert Akkerman:
>>
>>> __init__ is indeed the wrong place: when the instance is created it is
>>> not placed in an acquisition context yet.
>> That would indeed explain things!!! Is it okay to call a method which  
>> does this from __init__ ?
> 
> No, since the acquisition context is only created when the object is
> insert into the hierarchy somewhere (sloppy terminology here, I know).

Minor nit:  the acquisition wrappers are transient objects, created when
the object is retrieved from the container (typically via the
container's __getattr__).  So, the typical pattern for a factory which
needs to do something with context is:

  def foo_factory(container, name):
      foo = Foo(name)
      container._setObject(name, foo)
      wrapped = container._getOb(foo)
      # now we have context

> And that can only happen after the instance has been fully created.
> 
> As an example:
> 
>    obj = Object()
>    # obj has no acquisition context
>    folder.obj = obj
>    # folder.obj will have an acquisition context

Right, but the original 'obj' doesn't magically get a context:  you need
to re-fecth it (via 'foo.obj').

> In other words: in __init__ and everything you call from __init__ the
> instance will not have an aq context. The context does not magically
> appear.

Yup.



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHJ2ux+gerLs4ltQ4RAuWTAKDIhq+jyK7l7icmYax3HxxvZWmb2gCfU6dl
vmEUq8YkT+RFbxzUFet7Ybk=
=v4zr
-----END PGP SIGNATURE-----



More information about the Zope-CMF mailing list