zc.sourcefactory doesn't work out of the box

Bug #319546 reported by Jeroen Michiel
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grok
Fix Released
Undecided
Unassigned

Bug Description

If you add zc.sourcefactoy to install_requires in setup.py, it gets the latest version (0.4.0), which doesn't seem to be compatible with the other components grok uses.
If you use a schema.Choice field with a BasicSourceFactory, you get the error
ComponentLookupError: ((<zc.sourcefactory.source.FactoredSource object at 0x0259BE10>, <zope.publisher.browser.BrowserRequest instance URL=http://localhost :8080/arts/candidates/add>), <InterfaceClass zope.app.form.browser.interfaces.ITerms>, u'')

Pinning its version to 0.3.5 solves it, but perhaps we should try and use the latest version?

Revision history for this message
volker.jaenisch (volker-jaenisch) wrote :

With an actual fresh grokproject it seems that pinning to 0.3.5 does not work any longer.

  File "/opt/zope/fencing/vmmanager/eggs/zope.component-3.4.0-py2.5.egg/zope/component/_api.py", line 103, in getMultiAdapter
    raise ComponentLookupError(objects, interface, name)
ComponentLookupError: ((<zc.sourcefactory.source.FactoredContextualSource object at 0xaef0bac>, <zope.publisher.browser.BrowserRequest instance URL=http://localhost:8080/test/kvmManager/add>), <InterfaceClass zope.browser.interfaces.ITerms>, u'')

Revision history for this message
volker.jaenisch (volker-jaenisch) wrote :

Sorry. But I was in error. The stacktrace is similiar but the true error was not to include
zc.sourcefactory into the setup.py file as a dependency.

So I like to retract my bugreport.

Revision history for this message
Uli Fouquet (uli-gnufix) wrote :

Jeroen, I think the problem is caused by zc.sourcefactory dropping zope.app.form support with version 0.4 and switching to zope.browser, at least for the interface definition of ITerms.

So in zc.sourcefactory 0.4 there is no multi adapter from (FactoredSource, Request) to the zope.app.form ITerms available anymore. Instead this adapter now adapts to the ITerms of zope.browser.

A nasty workaround is to register the old adapter manually, roughly like this somewhere in your project:
--------------%<-----------------------
import grok
from zc.sourcefactory.browser.source import FactoredTerms
from zc.sourcefactory.source import FactoredSource
from zope.app.form.browser.interfaces import ITerms
from zope.publisher.interfaces.browser import IBrowserRequest

class OldFactoryTerms(FactoredTerms, grok.MultiAdapter):
    grok.provides(ITerms)
    grok.adapts(FactoredSource, IBrowserRequest)
--------------%<-----------------------

This way you should be able to use the newer zc.sourcefactory with grok projects, but this is hardly a way to go for grok in general. We cannot simply say, that our base class here (FactoredTerms) really provides the old ITerms interface. This might be true now, but for upcoming versions of zope.browser the interface might change and FactoredTerms accordingly. What then?

Furthermore we would have a configuration problem if someone wants to use zc.sourcefactory < 0.4 (conflicting adapter configs).

Therefore the workaround might be okay for applications that pin down versions for zc.sourcefactory and all that but it is (IMO) not a way for grok or any grokcore component.

I am tending to mark this as 'wont-fix', but maybe someone has a better idea?

Revision history for this message
Christian Klinger (cklinger) wrote :

We know that it did not work in grok 1.1, but
it works in grok 1.2.

By default we have in 1.2 the following version sets:

 zope.schema 3.7
 zc.sourcefactory 0.7

Changed in grok:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.