Re: non-concurrent QuerySet.get_or_create() on Postgresql

2017-10-16 Thread Ran Benita
The code tries to handle a scenario like the following (of course, the statements can be relatively ordered in different ways). Can you describe how the scenario which fails for you looks like? I am assuming you are using READ COMMITTED, and that the lookup fields are unique together. THREAD1

Re: non-concurrent QuerySet.get_or_create() on Postgresql

2017-10-16 Thread Дилян Палаузов
Hello The problem was, that get_or_create() was called within a transaction and at the end of the transaction the INSERT caused IntegrityError, as in the meantime another transaction has finished, that inserted the same row but with a different id. I have wrongly concluded, that repeating get

Re: non-concurrent QuerySet.get_or_create() on Postgresql

2017-10-12 Thread Ran Benita
Have you drilled down to `self._create_object_from_params(params)`? It does handle this case, as follows: try: with transaction.atomic(using=self.db): params = {k: v() if callable(v) else v for k, v in params.items()} obj = self.create(**params) return obj, True except Inte

non-concurrent QuerySet.get_or_create() on Postgresql

2017-10-01 Thread Дилян Палаузов
Hello, currently get_or_create(params) is implemented (imprecisely) this way: try: self.get(params) except DoesNotExist: self._create_object_from_params(params) This creates concurrency problem, as the object might get created by another thread, after get(params) threw an exception and bef