445 | | params = dict([(k, v) for k, v in kwargs.items() if '__' not in k]) |
446 | | params.update(defaults) |
447 | | obj = self.model(**params) |
448 | | sid = transaction.savepoint(using=self.db) |
449 | | obj.save(force_insert=True, using=self.db) |
450 | | transaction.savepoint_commit(sid, using=self.db) |
451 | | return obj, True |
452 | | except IntegrityError, e: |
453 | | transaction.savepoint_rollback(sid, using=self.db) |
454 | | exc_info = sys.exc_info() |
| 444 | read_db = self.db |
| 445 | self._for_write = True |
| 446 | if read_db == self.db: |
| 447 | raise self.model.DoesNotExist |
| 448 | return self.get(**lookup), False |
| 449 | except self.model.DoesNotExist: |
456 | | return self.get(**lookup), False |
457 | | except self.model.DoesNotExist: |
458 | | # Re-raise the IntegrityError with its original traceback. |
459 | | raise exc_info[1], None, exc_info[2] |
| 451 | params = dict([(k, v) for k, v in kwargs.items() if '__' not in k]) |
| 452 | params.update(defaults) |
| 453 | obj = self.model(**params) |
| 454 | sid = transaction.savepoint(using=self.db) |
| 455 | obj.save(force_insert=True, using=self.db) |
| 456 | transaction.savepoint_commit(sid, using=self.db) |
| 457 | return obj, True |
| 458 | except IntegrityError, e: |
| 459 | transaction.savepoint_rollback(sid, using=self.db) |
| 460 | exc_info = sys.exc_info() |
| 461 | try: |
| 462 | return self.get(**lookup), False |
| 463 | except self.model.DoesNotExist: |
| 464 | # Re-raise the IntegrityError with its original traceback. |
| 465 | raise exc_info[1], None, exc_info[2] |