def get_or_create(self, **kwargs):
        """
        This is a copy of QuerySet.get_or_create, that forces calling our custom
        create method when the get fails.
        """
        assert kwargs, \
                'get_or_create() must be passed at least one keyword argument'
        defaults = kwargs.pop('defaults', {})
        try:
            self._for_write = True
            return self.get(**kwargs), False
        except self.actual_model.DoesNotExist:
            params = dict([(k, v) for k, v in kwargs.items() if '__' not in k])
            params.update(defaults)
            obj = self.model(**params)
            self._for_write = True
            self._instance = obj
            using = self.db
            try:
                sid = transaction.savepoint(using=using)
                obj.save(force_insert=True, using=using)
            except IntegrityError, e:
                transaction.savepoint_rollback(sid, using=using)
                try:
                    return self.get(**kwargs), False
                except self.actual_model.DoesNotExist, e:
                    raise self.actual_model.DoesNotExist(unicode(e).replace(self.model.__name__, self.actual_model.__name__))
            else:
                transaction.savepoint_commit(sid, using=using)
                return obj, True
dataset/ETHPy150Open disqus/sharding-example/sqlshards/db/shards/manager.py/PartitionQuerySet.get_or_create/original