def _get_or_create(klass, **kwargs):
    try:
        return klass.objects.get(**kwargs)
    except klass.DoesNotExist:
        try:
            return klass.objects.create(**kwargs)
        except IntegrityError:
            return klass.objects.get(**kwargs)
Mimic logic Manager.get_or_create without savepoints
dataset/ETHPy150Open chop-dbhi/django-sts/sts/models.py/_get_or_create