'Lookup object in session or from DB based on a column\'s value.'

def _find_instance_by_column_value(self, session, model, column, value):

    for session_obj in session:
        if (not isinstance(session_obj, model)):
            continue
        if (getattr(session_obj, column) == value):
            return session_obj
    related_obj = session.query(model).filter_by(**{column: value}).first()
    return related_obj
