'Establish events that populate/expire the composite attribute.'

def _setup_event_handlers(self):

    def load_handler(state, *args):
        dict_ = state.dict
        if (self.key in dict_):
            return
        for k in self._attribute_keys:
            if (k not in dict_):
                return
        dict_[self.key] = self.composite_class(*[state.dict[key] for key in self._attribute_keys])
    def expire_handler(state, keys):
        if ((keys is None) or set(self._attribute_keys).intersection(keys)):
            state.dict.pop(self.key, None)
    def insert_update_handler(mapper, connection, state):
        'After    an    insert    or    update,    some    columns    may    be    expired    due\n                                                to    server    side    defaults,    or    re-populated    due    to    client    side\n                                                defaults.        Pop    out    the    composite    value    here    so    that    it\n                                                recreates.\n\n                                                '
        state.dict.pop(self.key, None)
    event.listen(self.parent, 'after_insert', insert_update_handler, raw=True)
    event.listen(self.parent, 'after_update', insert_update_handler, raw=True)
    event.listen(self.parent, 'load', load_handler, raw=True, propagate=True)
    event.listen(self.parent, 'refresh', load_handler, raw=True, propagate=True)
    event.listen(self.parent, 'expire', expire_handler, raw=True, propagate=True)
