def _safe_get(Model, **kwargs):
    object = None
    query = Model.objects.filter(**kwargs)
    count = query.count()
    if count > 1:
        stacklog.warn('Multiple records found for %s get.' % Model.__name__)
        object = query[0]
    elif count < 1:
        stacklog.warn('No records found for %s get.' % Model.__name__)
    else:
        object = query[0]
    return object
dataset/ETHPy150Open openstack/stacktach/stacktach/db.py/_safe_get/original