def _get_customer(request):
    user = request.user
    if user.is_authenticated():
        try:
            return Customer.objects.get(user=user)
        except __HOLE__:
            return None
    else:
        session_key = request.session.session_key
        try:
            return Customer.objects.get(session=session_key)
        except ObjectDoesNotExist:
            return None
        except MultipleObjectsReturned:
            customers = Customer.objects.filter(session=session_key, user__isnull=True)
            customer = customers[0]
            customers.exclude(pk=customer.pk).delete()
            return customer
dataset/ETHPy150Open diefenbach/django-lfs/lfs/customer/utils.py/_get_customer