def set(self, state, dict_, value, initiator,
            passive=PASSIVE_OFF, check_old=None, pop=False):
        if self.dispatch._active_history:
            old = self.get(
                state, dict_, passive=PASSIVE_ONLY_PERSISTENT | NO_AUTOFLUSH)
        else:
            # would like to call with PASSIVE_NO_FETCH ^ INIT_OK.  However,
            # we have a long-standing behavior that a "get()" on never set
            # should implicitly set the value to None.  Leaving INIT_OK
            # set here means we are consistent whether or not we did a get
            # first.
            # see test_use_object_set_None vs.
            # test_use_object_get_first_set_None in test_attributes.py
            old = self.get(state, dict_, passive=PASSIVE_NO_FETCH)

        if check_old is not None and \
                old is not PASSIVE_NO_RESULT and \
                check_old is not old:
            if pop:
                return
            else:
                raise ValueError(
                    "Object %s not associated with %s on attribute '%s'" % (
                        instance_str(check_old),
                        state_str(state),
                        self.key
                    ))

        value = self.fire_replace_event(state, dict_, value, old, initiator)
        dict_[self.key] = value
Set a value on the given InstanceState.
dataset/ETHPy150Open RoseOu/flasky/venv/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py/ScalarObjectAttributeImpl.set