yams #100723 Allow custom annotations [in-progress]

Why have custom annotations in Yams


Specifying an etype as container starts from schema.py:

def post_build_callback(schema):
    from cubes.container.utils import define_container
    from cubes.pagode.entities import tariff
    define_container(schema, 'TariffBox', 'tbox', skiprtypes=tariff.TariffBox.container_skiprtypes)

We found this at the orm level:

class TariffBox(AnyEntity):
    __regid__ = 'TariffBox'
    container_rtype = 'tbox'
    container_skip_rtypes = ('local_group',

And finally in hooks we adjust one selector:

def registration_callback(vreg):
    # setup container parent hook for the TariffBox container
    from cubes.container import hooks as chooks
    cetype, crtype = 'TariffBox', 'tbox'
    tboxclass = vreg['etypes'][cetype][0] # etype_class may not work here
    skiprtypes = tboxclass.container_skiprtypes
    tb_rtypes, _etypes = utils.container_static_structure(vreg.schema, cetype, crtype, skiprtypes)
    chooks.SetContainerParent.__select__ = (chooks.SetContainerParent.__select__ |
                                            (Hook.__select__ &  match_rtype(*tb_rtypes)))

We would like, in schema.py:

class TariffBox(EntityType):
      __container__ = {'crtype':     'to_the_container',
                       'skip_rtypes': ('local_group', 'require_permission')}
      name = String(...)

... and everything else be transparent.

Using containers as security contexts, one can imagine other annotations to help automate contained etypes/rtypes security rules.

Immutable attributes

This is currently written (given proper support) as:

class Case(AnyEntity):
    __regid__ = 'Case'
    immutable_rtypes = ('is_master', 'in_suitcase')

Would be nicer as:

class Case(EntityType):
    is_master = Boolean(immutable=True)

class in_suitcase(RelationDefinition):
    immutable = True

While it looks syntactically about the same, it would solve some tricky initialisation issues in the hooks.

appeared in<not specified>
done in1.0.0
closed by<not specified>
patchallow arbitrary notations in yams schema. Closes #100723, trhough different syntax [reviewed]