[Cubicweb] comma issue in StaticVocabularyConstraint, vocabulary

Aurélien Campéas aurelien.campeas at free.fr
Sun Aug 15 21:27:58 CEST 2010


Hi,

Le 13/08/10 00:20, Carlos Balderas a écrit :
> Hi everyone!
>
> I found this situation when using commas inside string values of
> StaticVocabularyConstraint and vocabulary when I was creating my
> schema.py file.
>
> The error thrown:
>
> /yams/constraints.py", line 346, in deserialize
>      return cls([eval(w) for w in value.split(', ')])
>    File "<string>", line 1
>       u'python
>              ^
>
> When it happens:
>
> At the moment to run the cube instance...
>
> When vocabulary values options have a comma and a SPACE inside the tuple
> element, for example : ('python, apache ...') this exception is thrown,
> in case you remove the SPACE after the comma like ('python,apache ...')
> every thing works fine.
>
> It should be noted that the scheme of the database is successfully
> created, this issue occurs at the moment of running the cube instance.
>
> The classmethod in question:
>
> /yams/constraints.py", line 346
>
> @classmethod
>      def deserialize(cls, value):
> """deserialize possible values from a csv list of evaluable strings"""
>          return cls([eval(w) for w in value.split(', ')])
>

I guess eval(w.strip()) for w in ...) would do it, but I'm curious to 
see why we eval there ...

>
> The test case:
>
> class TestVocabulary(EntityType):
>
>      attribute1 = String(vocabulary=('python', 'postgresql'
>                                      , 'apache', 'python, apache and
> postgresql' ))
>      attribute2 = String(constraints=[StaticVocabularyConstraint(
>                  ('python', 'postgresql'
>                   , 'apache', 'python, apache and postgresql'))])
>
>
> cubicweb changeset:   6107
>
> Best Regards
> Carlos Balderas
>
>
>
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb




More information about the Cubicweb mailing list