Opened 12 years ago
Closed 12 years ago
#19096 closed Cleanup/optimization (fixed)
SQLInsertCompiler and DatabaseOperations.return_insert_id for non standard backends
Reported by: | Michael Manfre | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I ran in to a problem with SQLInsertCompiler while trying to allow django-mssql to have can_return_id_from_insert = True
. The problem is that SQLInsertCompiler requires that an SQL fragment (returned by ops.return_insert_id) is appended to the end of the insert statement, but the fragment must also accept the full quoted table and column name.
https://github.com/django/django/blob/master/django/db/models/sql/compiler.py#L900
The problem for mssql, is that the OUTPUT clause doesn't conform to these two requirements and is better served by mangling the SQL query in its own SQLInsertCompiler. To make this possible (in a backwards compatible way), the output of return_insert_id needs to be checked and ignored if r_fmt is None.
Change History (3)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
RETURNING
is an extension of the SQL standard. We can't make assumptions about how the various databases implement it.Adding a
if r_fmt is None:
here looks harmless.I'm in favor of helping 3rd party database adapters when we can.