def get_related_publishes(to_check, fields=()):
    """Find all publishes which derive from the given ones.

    Looks in ``sg_source_publishes`` field of ``PublishEvent`` for any of
    the given publishes.

    :param list to_check: List of publish entities.
    :param list fields: Extra fields to fetch on derived publishes.
    :return: ``set`` of publish entities.

    """

    if not isinstance(to_check, (list, tuple)):
        to_check = [to_check]

    assert all(x['type'] == 'PublishEvent' for x in to_check)

    sg = to_check[0].session
    fields = tuple(fields) + ('source_publishes', )

    seen = set()
    related = set()

    while True:

        # Filter out those we have already looked at.
        to_check = [x for x in to_check if x not in seen]
        seen.update(to_check)

        if not to_check:
            break

        checking = to_check
        to_check = []

        # Find all sources of these publishes.
        sg.fetch(checking, ['source_publishes'])
        for x in checking:
            to_check.extend(x['source_publishes'] or ())

        # Find any that these are the source of.
        to_check.extend(sg.find('PublishEvent', [('source_publishes', 'in', checking)], fields))

        related.update(to_check)

    return related