Opened 7 years ago
Closed 7 years ago
#28675 closed Cleanup/optimization (fixed)
Tautology in sql/compiler/SQLInsertCompiler.execute_sql()
Reported by: | Дилян Палаузов | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the snippet below, not looking in the specifics of the cursor implementation, I don't think that cursor can evaluate to False, as otherwise cursor.execute() on the line before would have failed. I propose deleting "and cursor":
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1256,19 +1256,19 @@ class SQLInsertCompiler(SQLCompiler): def execute_sql(self, return_id=False): assert not ( return_id and len(self.query.objs) != 1 and not self.connection.features.can_return_ids_from_bulk_insert ) self.return_id = return_id with self.connection.cursor() as cursor: for sql, params in self.as_sql(): cursor.execute(sql, params) - if not (return_id and cursor): + if not (return_id and cursor): # tautology since 7deb25b8dd5aa1 return if self.connection.features.can_return_ids_from_bulk_insert and len(self.query.objs) > 1: return self.connection.ops.fetch_returned_insert_ids(cursor) if self.connection.features.can_return_id_from_insert: assert len(self.query.objs) == 1 return self.connection.ops.fetch_returned_insert_id(cursor) return self.connection.ops.last_insert_id( cursor, self.query.get_meta().db_table, self.query.get_meta().pk.column )
Change History (2)
comment:1 by , 7 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Has patch: | set |
Triage Stage: | Unreviewed → Ready for checkin |
Type: | Uncategorized → Cleanup/optimization |
Note:
See TracTickets
for help on using tickets.
PR