[ZODB-Dev] Trouble with 'transaction' module

Tim Peters tim.peters at gmail.com
Tue Jan 31 11:40:01 EST 2006


[Andreas Jung]
> I have the following code in side a Plone app. The intent of this method is
> to perform a logging of changed Archetype fields. This code basically works
> but under some unknown circumstances I get error below where the
> transaction module seems to be None?!  There is no product refreshing
> enabled. I am using Zope 2.8.5....any ideas?

There's certainly nothing ZODB does that can reach into _your_ module
and change the binding of your module-global name "transaction".  This
really has nothing to do with the transaction module, it has to do
with module-global name bindings, one of which happens to be named
"transaction" here.

Python itself rebinds a module's global names to None as part of
tearing a module down (part of module destruction).  "This or that
can't be None" is an irritatingly common exception seen during Python
shutdown as a result, when various user-defined cleanup code happens
to run after Python has "None'd out" the globals of the module
containing such code.

If this is happening during shutdown, that's probably it.  But this
looks like some "funny way" of running Python code I don't know much
about, perhaps with its own inscrutable rules about what happens to
module globals.

As a workaround, you could try moving the import inside the function,
so that "transaction" becomes a local name in your function rather
than a global name in your module.

> Andreas
>
> --------
>
>
> import transaction
>
> def post_validate(self, REQUEST, errors):
>     """ hook into AT(CT) to intercept edit operations to provide
>         logging for changed data.
>     """
>
>     T = transaction.get()
>     CH = CommitHandler()
>     CH.setInstance(self)
>     T.beforeCommitHook(CH)
>
>     return self._post_validate(REQUEST, errors)
>
>
> --------
>
>  File
> "/develop/sandboxes/plone2.1/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
> line 311, in __call__
>     return self._bindAndExec(args, kw, None)
>   File
> "/develop/sandboxes/plone2.1/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
> line 348, in _bindAndExec
>     return self._exec(bound_data, args, kw)
>   File
> "/develop/sandboxes/plone2.1/instance/Products/CMFCore/FSPythonScript.py",
> line 163, in _exec
>     result = f(*args, **kw)
>   File "Script (Python)", line 23, in validate_atct
>   File
> "/develop/sandboxes/plone2.1/instance/Products/Archetypes/BaseObject.py",
> line 504, in validate
>     self.post_validate(REQUEST, errors)
>   File
> "/develop/sandboxes/plone2.1/instance/Products/SRMedia/monkeypatches.py",
> line 72, in post_validate
>     return self._post_validate(REQUEST, errors)
>   File
> "/develop/sandboxes/plone2.1/instance/Products/SRMedia/monkeypatches.py",
> line 67, in post_validate
>     T = transaction.get()
> AttributeError: 'NoneType' object has no attribute 'get'
>
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zodb-dev


More information about the ZODB-Dev mailing list