[Grok-dev] Re: Problems rendering zope.schema.List

Tres Seaver tseaver at palladion.com
Tue Jul 17 16:33:52 EDT 2007

Hash: SHA1

Luciano Ramalho wrote:
> On 7/5/07, Tres Seaver <tseaver at palladion.com> wrote:
>> "Danger, Will Robinson!".  Mutable defaults are not going to produce
>> happy results, at least if the 'List' implementation mutates them.
>> List should be checking for None internally, and adding its own *new*
>> empty list if no value is passed (Python will recycle the one created by
>> the list literal across *all* uses).
> Thanks for the warning, Tres!
> I am aware of the pitfalls of using mutable values in default args.
> However, because the solution I mentioned was suggested by Philipp,

It *can't* be safe, because you have no guarantees that the value will
not be mutated by code elsewhere in the application.

> I > assumed it was safe to do it in that particular case (setting an empty
> list as default value for a List field to prevent an auto-generated
> add form from choking while iterating over None).

The *widget* should handle the case where the default value is None,
here:  there is *no* reasonable default value for a list widget that can
be spelled as an attribute of the field at declaration time.

> I've spent some time since then trying to find "proper" way to solve
> this. For example, I tried using an empty tuple instead of a list, but
> I got "WrongType: ((), <type 'list'>)" (I hope the javaification of
> Python in Zope 3 doesn't go much further).

Schemas which specify default values should ideally take a callable
which returns a value;  one option is to try calling the 'valuetype' of
the field.

> It seems the only way to really solve this is patching the
> implementation of the Zope 3 list field itself. But I am amazed this
> has never bitten anyone before Sebastian and me. What am I missing?

Maybe nobody is using the 'List' schema field type in "real world"

- --
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the Grok-dev mailing list