def add_or_update(
        cls, model_object, publish=True, dispatch_trigger=True, validate=True
    ):
        """
        Note: We override add_or_update because we also want to publish high level "value_change"
        event for this resource.
        """
        if model_object.id:
            existing_model_object = cls.get_by_id(value=model_object.id)
        else:
            # Not an update
            existing_model_object = None

        model_object = super(KeyValuePair, cls).add_or_update(
            model_object=model_object,
            publish=publish,
            dispatch_trigger=dispatch_trigger,
        )

        # Dispatch a value_change event which is specific to this resource
        if existing_model_object and existing_model_object.value != model_object.value:
            cls.dispatch_value_change_trigger(
                old_model_object=existing_model_object, new_model_object=model_object
            )

        return model_object

        Note: We override add_or_update because we also want to publish high level "value_change"
        event for this resource.
        
st2common/st2common/persistence/keyvalue.py