cubicweb #17098068 Missing a default value converter for Bytes [open]

With a schema like

from yams.buildobjs import EntityType, Bytes

class A(EntityType):
    attr = Bytes(default='yo')

... when you create an instance of A (with create_entity in a cubicweb shell or using the web GUI), you get an error as the default value is converted to a unicode which is unsuitable for the storage backend.

Following code seems to fix it

from six import binary_type
from yams import DATE_FACTORY_MAP as FACTORY_MAP
from cubicweb import Binary

FACTORY_MAP['Bytes'] = lambda x: x if isinstance(x, Binary) else Binary(binary_type(x))

Note that we suggest renaming DATE_FACTORY_MAP into FACTORY_MAP in yams and use something in like in CW:

if getattr(yams, 'FACTORY_MAP', None) is not None:
    FACTORY_MAP = yams.FACTORY_MAP
else:
    FACTORY_MAP = yams.DATE_FACTORY_MAP
prioritynormal
typebug
done in<not specified>
closed by<not specified>