def get_trigger_db_by_ref_or_dict(trigger):
    """
    Retrieve TriggerDB object based on the trigger reference of based on a
    provided dictionary with trigger attributes.
    """
    # TODO: This is nasty, this should take a unique reference and not a dict
    if isinstance(trigger, six.string_types):
        trigger_db = get_trigger_db_by_ref(trigger)
    else:
        # If id / uid is available we try to look up Trigger by id. This way we can avoid bug in
        # pymongo / mongoengine related to "parameters" dictionary lookups
        trigger_id = trigger.get("id", None)
        trigger_uid = trigger.get("uid", None)

        # TODO: Remove parameters dictionary look up when we can confirm each trigger dictionary
        # passed to this method always contains id or uid
        if trigger_id:
            LOG.debug("Looking up TriggerDB by id: %s", trigger_id)
            trigger_db = get_trigger_db_by_id(id=trigger_id)
        elif trigger_uid:
            LOG.debug("Looking up TriggerDB by uid: %s", trigger_uid)
            trigger_db = get_trigger_db_by_uid(uid=trigger_uid)
        else:
            # Last resort - look it up by parameters
            trigger_type = trigger.get("type", None)
            parameters = trigger.get("parameters", {})

            LOG.debug(
                "Looking up TriggerDB by type and parameters: type=%s, parameters=%s",
                trigger_type,
                parameters,
            )
            trigger_db = get_trigger_db_given_type_and_params(
                type=trigger_type, parameters=parameters
            )

    return trigger_db

    Retrieve TriggerDB object based on the trigger reference of based on a
    provided dictionary with trigger attributes.
    
st2common/st2common/services/triggers.py