--
Ticket URL: <https://code.djangoproject.com/ticket/30138>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Old description:
> According to [https://code.djangoproject.com/ticket/28668#comment:24]
> comment, I create new ticket for returning pk of created objects. I tried
> it in Postgresql 10.6 and this subject is supported. I see that when
> ignore_confilicts set as True, django api doesn't put ' RETURNING
> "mymodel"."id" ' in query.
New description:
As requested in ticket:28668#comment:24, here's a ticket for setting the
primary keys of created objects. I tried it in PostgreSQL 10.6 and this
could be supported. When `ignore_confilicts=True`, Django doesn't put `'
RETURNING "mymodel"."id" '` in the query.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:1>
* status: new => assigned
* owner: nobody => Seunghun Lee
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:2>
Comment (by Дилян Палаузов):
At https://code.djangoproject.com/ticket/28668 are attached patches, that
accomplish this.
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:3>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10998 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:4>
* status: assigned => new
* owner: Seunghun Lee => (none)
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:5>
* owner: (none) => Hasan Ramezani
* status: new => assigned
Comment:
Based on the ticket description we should add `' RETURNING "mymodel"."id"
'` to the query when `ignore_confilicts=True`. But based on the
[https://github.com/django/django/pull/12233#issuecomment-567965748 Simon
comment on the PR] `the database will not return any conflicting row ids`.
I am a little confused because of the Database just returns newly created
object ids. Check Simon's example in the comment.
What should we do?
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:6>
Comment (by Simon Charette):
Hasan, this was mentioned in
https://code.djangoproject.com/ticket/28668#comment:21 but was dismissed
as something
[https://code.djangoproject.com/attachment/ticket/28668/on_conflict_ignore.patch
the proposed implementation] would take of.
It does so by doing a `LEFT JOIN` over the existing rows and would require
a set of columns against which to join to be provided to the call.
Implementing this in a proper manager would likely require a lot of work.
It would require `ignore_conflicts` to accept an iterable of constraint
names or tuple of fields corresponding to `Field.unique=True` or
`Meta.unique_together` definitions. These entries could then be matched to
constraint names and used as `conflict_target` in the `ON CONFLICT` clause
and in the join `USING` clause. I think we'd also like to allow exclusion
constraints to be treated differently because joining on fields won't help
here as an insert could be conflicting with more than one result.
I assume callers would also like to be able to differentiate between newly
inserted and conflicting entries so the return value of `bulk_create`
would need to be formalized/changed.
In summary this ticket involves a lot of research work to get right and
not paint ourselves in a corner with regards to the desired API.
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:7>
* owner: Hasan Ramezani => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:8>
* cc: Alex Vandiver (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30138#comment:9>