Ticket #7402: get_or_create.diff
File get_or_create.diff, 963 bytes (added by , 16 years ago) |
---|
-
django/db/models/query.py
330 330 obj.save() 331 331 return obj, True 332 332 except IntegrityError, e: 333 return self.get(**kwargs), False 333 # If transactions are managed manually, we must fail. 334 if transaction.is_managed(): 335 raise e 336 # Try to get object, maybe this was just concurrency error. 337 try: 338 transaction.rollback_unless_managed() 339 obj = self.get(**kwargs) 340 except self.model.DoesNotExist: 341 # No object found, re-raise error. 342 raise e 343 return obj, False 334 344 335 345 def latest(self, field_name=None): 336 346 """