def dispatch_with_context(
        self, trigger, payload=None, trace_context=None, throw_on_validation_error=False
    ):
        """
        Method which dispatches the trigger.

        :param trigger: Reference to the TriggerTypeDB (<pack>.<name>) or TriggerDB object.
        :type trigger: ``str``

        :param payload: Trigger payload.
        :type payload: ``dict``

        :param trace_context: Trace context to associate with Trigger.
        :type trace_context: ``st2common.api.models.api.trace.TraceContext``

        :param throw_on_validation_error: True to throw on validation error (if validate_payload is
                                          True) instead of logging the error.
        :type throw_on_validation_error: ``boolean``
        """
        # Note: We perform validation even if it's disabled in the config so we can at least warn
        # the user if validation fals (but not throw if it's disabled)
        try:
            validate_trigger_payload(
                trigger_type_ref=trigger,
                payload=payload,
                throw_on_inexistent_trigger=True,
            )
        except (ValidationError, ValueError, Exception) as e:
            self._logger.warning(
                'Failed to validate payload (%s) for trigger "%s": %s'
                % (str(payload), trigger, six.text_type(e))
            )

            # If validation is disabled, still dispatch a trigger even if it failed validation
            # This condition prevents unexpected restriction.
            if cfg.CONF.system.validate_trigger_payload:
                msg = (
                    "Trigger payload validation failed and validation is enabled, not "
                    'dispatching a trigger "%s" (%s): %s'
                    % (trigger, str(payload), six.text_type(e))
                )

                if throw_on_validation_error:
                    raise ValueError(msg)

                self._logger.warning(msg)
                return None

        self._logger.debug("Dispatching trigger %s with payload %s.", trigger, payload)
        return self._dispatcher.dispatch(
            trigger, payload=payload, trace_context=trace_context
        )

        Method which dispatches the trigger.

        :param trigger: Reference to the TriggerTypeDB (<pack>.<name>) or TriggerDB object.
        :type trigger: ``str``

        :param payload: Trigger payload.
        :type payload: ``dict``

        :param trace_context: Trace context to associate with Trigger.
        :type trace_context: ``st2common.api.models.api.trace.TraceContext``

        :param throw_on_validation_error: True to throw on validation error (if validate_payload is
                                          True) instead of logging the error.
        :type throw_on_validation_error: ``boolean``
        
st2common/st2common/services/trigger_dispatcher.py