Two zope.schema and z3c.form vocabulary/source bugs
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Won't Fix
|
Undecided
|
Unassigned | ||
zope.schema |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
I've been trying to get a Choice schema field populated by a sql database load, and have run into 2 bugs/inconsiste
#1. in zope.schema.
"""
...
Because registered vocabularies are simply callables passed a context, many
registered vocabularies can simply be functions that rely on SimpleVocabulary:
>>> from zope.schema.
>>> def myDynamicVocabu
... v = dynamic_
... return SimpleVocabular
"""
This suggested "shortcut" is wrong because at line 201 of /export/
def __init__(self, values=None, vocabulary=None, source=None, **kw):
if vocabulary is not None:
assert (isinstance(
The documentation is suggesting a feature that is no longer supported due to the hard assertion of IBaseVocabulary, which the function is not capable of doing. I suggest making it clear how vocaulary="..." on a field is meant to support a contextual result.
#2. Giving up on vocabularies, I looked at the situation with source="..." field parameter, specifying an IContextSourceB
sensorId = schema.Choice(title = u'Sensor',
and providing the Sensors2.
class FieldSourceBind
interface.
def __call__(self, context):
"""Return the list or {sensor_id: sensor_name} from t_sensor"""
# Database read into sensors variable omitted
return SimpleVocabular
things break. It is because the z3c.form.term.Terms terms attribute is now a IContextSourceB
Module z3c.form.form, line 189, in __call__
Module z3c.form.form, line 184, in update
Module z3c.form.form, line 134, in update
Module z3c.form.form, line 126, in updateWidgets
Module z3c.form.field, line 259, in update
Module z3c.form.
Module z3c.form.term, line 40, in __iter__
TypeError: iteration over non-sequence
> /export/
-> return iter(self.terms)
(Pdb) print self.terms
<wastac.
Why is this just so hard and what is the right way to get a dynamically populated Choice? This is my first foray into zope3 and it's been trial by fire to be honest.
Changed in zope3: | |
status: | New → Won't Fix |
As a quick fix solution, you can register your vocabulary factory as a named utility and pass the name as the "vocabulary" argument.
However, this things should certainly be looked at and fixed, thanks for the report.