#36189: Oracle Backend with `"use_returning_into": False` Option Fails to
Retrieve
Last Inserted ID
-------------------------------------+-------------------------------------
Reporter: Yeongbae Jeon | Owner: Amaan-
| ali03
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Yeongbae Jeon):
Replying to [comment:4 Simon Charette]:
> Another reason why `use_returning_into=False` is broken is that it
`SELECT sequence_name.currval` doesn't account for concurrent `INSERT`.
From what I understand, just like in Postgres, Oracle sequences are not
tied to transactions which means that nothing prevents a concurrent
`INSERT` from being executed in a separate transaction and increasing the
sequence before it can be `SELECT`ed.
>
> e.g.
>
> - session0: `INSERT`
> - session1: `INSERT`
> - session0: `SELECT sequence_name.currval`
> - session1: `SELECT sequence_name.currval`
>
> Both session 0 and 1 assume that their `last_insert_id` is the same;
session 0 is wrong.
I agree with you. Another case I can think of (although I haven't tested
it yet, so please correct me if I'm wrong, as this is based on my limited
experience) is when a user explicitly provides a value for the primary key
while creating an object, instead of relying on the nextval from the
sequence.
For example, if the currval of the sequence is 1, but the user manually
assigns 10 as the primary key when creating the object, then
use_returning_into: False will execute the last_insert_id function, which
will return the incorrect value of 1.
--
Ticket URL: <https://code.djangoproject.com/ticket/36189#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019519cb27cb-6698ebe4-fd00-4971-88ce-74522295d80c-000000%40eu-central-1.amazonses.com.