When I call `get_or_create` I expect it to return the existing record, or
to create a new record if one does not exist yet. Getting an
`IntegrityError` there is like saying "there's no existing record, but I
cannot create a new one because one already exists".
--
Ticket URL: <https://code.djangoproject.com/ticket/24009>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
This may be a duplicate of #13906. Are you using MySQL with `REPEATABLE
READ`?
--
Ticket URL: <https://code.djangoproject.com/ticket/24009#comment:1>
Comment (by lanzz):
No, I'm using PostgreSQL, and wrapping each `get_or_create` in an
individual transaction context will again make `get_or_create` worthless
by requiring at least as much boilerplate around it as it would take to
implement the get-or-create logic myself without using `get_or_create`.
--
Ticket URL: <https://code.djangoproject.com/ticket/24009#comment:2>
Comment (by timgraham):
As far as I can tell, the `IntegrityError` you describe
[https://github.com/django/django/blob/6403e07c5093e0244497293f31f5f73cebe85b66/django/db/models/query.py#L468-L483
should be caught by Django]. Did you run into this problem with Django
1.7?
--
Ticket URL: <https://code.djangoproject.com/ticket/24009#comment:3>
* status: new => closed
* resolution: => needsinfo
--
Ticket URL: <https://code.djangoproject.com/ticket/24009#comment:4>