[Zope-CMF] Bug: 'TypeError: cannot convert string to tuple' in metadata_edit

Tres Seaver tseaver@palladion.com
Sat, 14 Jul 2001 11:03:21 -0400 (EDT)


On Sat, 14 Jul 2001, [iso-8859-1] Gr=E9goire Weber wrote:

> Hi Seb,
>=20
> > > When I call metadata_edit directly from the browser with a=20
> > > parameter which is internaly represented by a tuple like=20
> > > 'contributors' or subject I get a error, if the parameter
> > > occurs once only:
> > >    http://path/to/obj/metadata_edit?contributors=3Dx
> >=20
> > This is what the type coercion rules are for:
> >=20
> >   http://path/to/obj/metadata_edit?contributors:list=3Dx
>=20
> You're right. This works!
> And http://path/to/obj/metadata_edit?contributors:lines=3Dx also.
>=20
> > Your patch is a more robust way of dealing with this kind of
> > thing, though.  I wonder where the responsibility for ensuring type
> > correctness should lie?
>=20
> That's a good question! I don't see the implications in depth!
> The question is: Are these types real types describing the datas
> structure or the datas presentation (in HTML)?
>=20
> Consider this (original code snippet out of metadata_edit_form):
>=20
> <textarea name=3D"subject:lines" rows=3D"3"
>                           ^--------------------------- this!
>  cols=3D"20"><dtml-in Subject
>  ><dtml-let item=3Dsequence-item
>  ><dtml-unless expr=3D"item in allowedSubjects"
>  ><dtml-var sequence-item>
>  </dtml-unless></dtml-let></dtml-in></textarea>
>  <dtml-comment>
>  Comment out / delete this to ignore controlled vocabulary=20
>  for Subject.
>  </dtml-comment>
>  <br>
>  <select name=3D"subject:list" multiple>
>                         ^------------------------------ and this!
>  <dtml-in allowedSubjects>
>  <dtml-let item=3Dsequence-item
>  sel=3D"item in contentSubject and 'selected' or ''">
>  <option value=3D"&dtml-sequence-item;"
>  &dtml-sel;> &dtml-sequence-item; </option>
>  </dtml-let>
>  </dtml-in>
>  </select>
>=20
> The question which arrises (for me):
>    Is subject of type lines or of type list? Hmmm!

The issue is not whether subject is of those types (it is neither),
but how you want to have ZPublisher marshall the 'subject' form
variable:

  - ':list' says to ZPublisher, "Marshall this variable as
    a list, with an entry for each distinct value passed by
    the browser, even when the browser supplies only one value;
   =20
  - ':lines' says, "Split the single value supplied by the browser
    into mutiple values, breaking at newlines;
   =20
  - ':tokens' says, "Split the single value supplied by the browser
    into mutiple values, breaking at spaces;

  - ':int' says, "Convert the value supplied by the browser into
    an integer."

etc.
=20
> I had some problems a few days ago when I customized=20
> metadata_edit_form by puting the <select ...> block before the=20
> <textarea ...> block! Perhaps its the same source of problems.

Hmm, I don't know there;  I would suspect that ZPublisher needs
to know that the value is to be marshalled as a list when it
first encounters it;  in that case, you might need to use
':lines:list' (untested).

Tres
--=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Tres Seaver                                tseaver@digicool.com
Digital Creations     "Zope Dealers"       http://www.zope.org