本地实用程序用作产品依赖项的问题

发布于 2024-11-27 10:58:33 字数 3045 浏览 3 评论 0 原文

问题就在这里。我有 mynamespace.mypackage 作为依赖项 mynamespace.mydependencypackage,即 本地实用程序。它是使用组件注册表注册的。

mynamespace.mypackageconfig.py 中,我

DEPENDENCIES = ['mynamespace.mydependencypackage']

在我的 mynamespace.mypackagesetuphandlers.py 中如果尚未安装,则安装此依赖项。

问题是:如果我通过 ZMI 重新安装 mynamespace.mypackage,一切似乎都完美安装(因为没有显示错误),但我不断收到 ComponentLookupError > 当使用 mynamespace.mypackage 中获取实用程序的方法时:

Module zope.component._api, line 207, in getUtility
ComponentLookupError: (<InterfaceClass MY_UTILITY_INTERFACE, '')

我可以通过在我的 mynamespace.mypackage 中重新安装 mynamespace.mydependencypackage 来“修复”此问题setuphandlers.py 或在重新安装 mynamespace.mypackage 时通过 ZMI,但这对我来说似乎不是最佳解决方案。

我在这里缺少关于通用设置的什么?我没有让这个实用程序在 ZODB 上保留任何价值。我可以忘记所有这些问题并使用实用程序方法创建一个 BrowserView ,但我想首先了解为什么我会遇到这些问题。

编辑:现在,我有一个更大的问题。 TypeError: ('object.__new__(MyClass) 不安全,请使用 Persistence.Persistent.__new__()', , ( ;, , None)) 正在显示。完整回溯:

Traceback (innermost last):
  Module ZPublisher.Publish, line 110, in publish
  Module ZPublisher.BaseRequest, line 429, in traverse
  Module ZPublisher.BeforeTraverse, line 99, in __call__
  Module Products.CMFCore.PortalObject, line 94, in __before_publishing_traverse__
  Module zope.event, line 23, in notify
  Module zope.component.event, line 26, in dispatch
  Module zope.component._api, line 130, in subscribers
  Module zope.component.registry, line 290, in subscribers
  Module zope.interface.adapter, line 535, in subscribers
  Module zope.component.event, line 33, in objectEventNotify
  Module zope.component._api, line 130, in subscribers
  Module zope.component.registry, line 290, in subscribers
  Module zope.interface.adapter, line 535, in subscribers
  Module zope.app.component.site, line 375, in threadSiteSubscriber
  Module zope.app.component.hooks, line 61, in setSite
  Module Products.CMFCore.PortalObject, line 75, in getSiteManager
  Module ZODB.Connection, line 761, in setstate
  Module ZODB.Connection, line 819, in _setstate
  Module ZODB.serialize, line 604, in setGhostState
  Module ZODB.serialize, line 597, in getState
  Module copy_reg, line 48, in _reconstructor
TypeError: ('object.__new__(MyClass) is not safe, use Persistence.Persistent.__new__()', <function _reconstructor at 0xb7783e9c>, (<class 'mynamespace.mydependencypackage.package.MyClass'>, <type 'object'>, None))

Here's the problem. I have mynamespace.mypackage that has as a dependency mynamespace.mydependencypackage, that is a local utility. It's registered using component registry.

In config.py from mynamespace.mypackage, I have

DEPENDENCIES = ['mynamespace.mydependencypackage']

And in my mynamespace.mypackage's setuphandlers.py this dependency is installed if not already installed.

Problem is: if I reinstall mynamespace.mypackage through ZMI, everything seems to perfectly install (since no errors are shown) but I keep getting a ComponentLookupError when using methods in mynamespace.mypackage that gets the utility:

Module zope.component._api, line 207, in getUtility
ComponentLookupError: (<InterfaceClass MY_UTILITY_INTERFACE, '')

I can 'fix' this problem, by reinstalling the mynamespace.mydependencypackage in my setuphandlers.py or through the ZMI as well when reinstalling mynamespace.mypackage, but this doesn't seem the best solution for me.

What am I missing about Generic Setup here? I didn't make this utility persist any value on ZODB whatsoever. I can just forget about all these problems and create a BrowserView with utilities methods, but I want to understand first why am I having these problems.

EDIT: Now, I have a bigger problem. The TypeError: ('object.__new__(MyClass) is not safe, use Persistence.Persistent.__new__()', <function _reconstructor at 0xb7783e9c>, (<class 'mynamespace.mydependencypackage.package.MyClass'>, <type 'object'>, None)) is being shown. Full traceback:

Traceback (innermost last):
  Module ZPublisher.Publish, line 110, in publish
  Module ZPublisher.BaseRequest, line 429, in traverse
  Module ZPublisher.BeforeTraverse, line 99, in __call__
  Module Products.CMFCore.PortalObject, line 94, in __before_publishing_traverse__
  Module zope.event, line 23, in notify
  Module zope.component.event, line 26, in dispatch
  Module zope.component._api, line 130, in subscribers
  Module zope.component.registry, line 290, in subscribers
  Module zope.interface.adapter, line 535, in subscribers
  Module zope.component.event, line 33, in objectEventNotify
  Module zope.component._api, line 130, in subscribers
  Module zope.component.registry, line 290, in subscribers
  Module zope.interface.adapter, line 535, in subscribers
  Module zope.app.component.site, line 375, in threadSiteSubscriber
  Module zope.app.component.hooks, line 61, in setSite
  Module Products.CMFCore.PortalObject, line 75, in getSiteManager
  Module ZODB.Connection, line 761, in setstate
  Module ZODB.Connection, line 819, in _setstate
  Module ZODB.serialize, line 604, in setGhostState
  Module ZODB.serialize, line 597, in getState
  Module copy_reg, line 48, in _reconstructor
TypeError: ('object.__new__(MyClass) is not safe, use Persistence.Persistent.__new__()', <function _reconstructor at 0xb7783e9c>, (<class 'mynamespace.mydependencypackage.package.MyClass'>, <type 'object'>, None))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏见 2024-12-04 10:58:33

听起来您的 setuphandlers.py 文件中有自定义 Python 代码来安装依赖项。您是否有原因没有注意到metadata.xml 文件中的依赖关系?或者您可以向我们展示该代码吗?

在 Plone 中激活附加组件时,它会对各种实体进行前后比较以支持停用。其中包括本地持久实用程序,由 componentregistry.xml 文件定义。注意:GenericSetup xml 文件中定义的任何内容都会导致持久性更改 - 如果您需要非持久性实用程序,请使用 ZCML 文件来注册它们。

因此,当您有自定义代码在 setuphandlers.py 代码中添加本地实用程序时,Plone 认为该实用程序属于您的主要附加组件。如果您重新安装该附加组件,该实用程序将与其他任何内容一起被删除,然后所有内容都会重新安装。

我猜您的“是否已经安装”检查在重新安装后失败,并且该实用程序不会再次添加。

您可以通过简单地为依赖项和主要附加组件提供它们自己的 GenericSetup 配置文件,然后在主要的metadata.xml 中注明依赖项,来避免所有这些,例如:

<?xml version="1.0"?>
<metadata>
  <version>1</version>
  <dependencies>
    <dependency>profile-my.dependency:default</dependency>
  </dependencies>
</metadata>

一旦您这样做,依赖项配置文件将独立激活,并且 Plone 保留自己跟踪它。如果您随后决定重新安装主附加组件,则依赖项根本不会受到影响并保持不变。

It sounds like you have custom Python code in your setuphandlers.py file to install the dependency. Is there a reason you don't note the dependency in the metadata.xml file? Or can you show us that code?

When activating an add-on in Plone, it does a before/after comparison of various entities to support deactivation. Among these are local persistent utilities, as defined by the componentregistry.xml file. Note: anything defined in GenericSetup xml files results in persistent changes - if you want non-persistent utilities, use ZCML files to register them.

So when you have custom code to add a local utility in your setuphandlers.py code, Plone thinks this utility belongs to your main add-on. If you reinstall that add-on the utility gets removed alongside anything else and then everything is installed again.

I'm guessing your "is it already installed" check fails after the reinstall and the utility isn't added again.

You can avoid all of this, by simple giving both the dependency and main add-on their own GenericSetup profiles and than noting a dependency in the main's metadata.xml, like:

<?xml version="1.0"?>
<metadata>
  <version>1</version>
  <dependencies>
    <dependency>profile-my.dependency:default</dependency>
  </dependencies>
</metadata>

Once you do that the dependencies profile will be activated independently and Plone keeps track of it on its own. If you then decide to reinstall the main add-on, the dependency won't be touched at all and remains intact.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文