def _get_historical_value(attr):
    """ Get the previous value of an attribute

        This is where the magic happens: this method goes into the SqlAlchemy instance and
        obtains the historical value of an attribute called `key`
    """
    history = attr.history
    if not history.deleted:
        return attr.value
    else:
        return history.deleted[0]
