﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36189	"Deprecate `""use_returning_into"" database option."	Yeongbae Jeon	Yeongbae Jeon	"When running tests in `django-docker-box` with Oracle, setting the `""use_returning_into"": False` option in `settings.py` prevents Django from retrieving the last inserted ID. The issue can be reproduced by modifying the database options as shown below:  

{{{
if engine.endswith("".oracle""):
    entry |= {
        ""NAME"": name,
        ""OPTIONS"": {
            ""use_returning_into"": False,
        }
    }
    ...
}}}

**Cause of the Issue**
The issue originates from the `last_insert_id()` method in `django/db/backends/oracle/operations.py`. The SQL executed in this method does not properly handle the query format, leading to a failure in retrieving the sequence value.  

**Current Implementation (Buggy Code)**

{{{
def last_insert_id(self, cursor, table_name, pk_name):
    sq_name = self._get_sequence_name(cursor, strip_quotes(table_name), pk_name)
    cursor.execute('""%s"".currval' % sq_name)
    return cursor.fetchone()[0]

}}}


**Proposed Fix**  
The issue can be resolved by modifying the query to include the correct SQL syntax:  

{{{
def last_insert_id(self, cursor, table_name, pk_name):
    sq_name = self._get_sequence_name(cursor, strip_quotes(table_name), pk_name)
    template = 'SELECT ""%s"".currval' + self.connection.features.bare_select_suffix

    cursor.execute(template % sq_name)
    return cursor.fetchone()[0]

}}}"	Cleanup/optimization	assigned	Database layer (models, ORM)	5.1	Normal			Yeongbae Jeon Amaan-ali03 Mariusz Felisiak Simon Charette	Accepted	1	0	0	1	0	0
