Peter Bengtsson wrote at 2006-1-30 18:54 +0000:
>I've noticed another strange behaviour with the Acquisition module in
>Zope 2.9 that might give us some clues as to why refreshing doesn't
>Imagine some code that looks like this::
>from Acquisition import aq_parent
>class MyProduct(Folder):
>    def index_html(self):
>        print type(aq_parent) is None
>        return "Hello World!"
>The first time I run this, it prints "False" to stdout because
>ac_parent is of course a function.
>BUT, if I refresh the product (no change made to the source) and run
>this index_html() again it instead prints "True" because ac_parent has
>become None.
>Isn't that odd?

Indeed, especially because no type can be "None"!

It is known that refreshing (more generally reloading a Python module)
can cause objects apparently becoming "None".
This happens because the variables defined in the old module
instance are rebound to None when the module is released.

This would explain that "aq_parent" in your "index_html" would
appear as None if you happen to access an object still associated
with the old class. However, the type of "None" is "NoneType" and
not "None".

I do not yet know what magic can cause "type(aq_parent)"
(which usually is "<type 'builtin_function_or_method'>)
to become "None".

As written earlier: refreshing is essentially a Python feature
(delete a set of modules from "sys.modules", then reimport some of
them again) rather than a Zope feature.
It should be possible to reproduce your weird observations
with Python operations only.
I tried but was not yet able to reproduce it (I still use Zope 2.8
(but that should not matter) and Python 2.4.1).

Zope maillist  -
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to