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 Tim Graham, 7 years ago

Component: UncategorizedDatabase layer (models, ORM)
Has patch: set
Triage Stage: UnreviewedReady for checkin
Type: UncategorizedCleanup/optimization

comment:2 by GitHub <noreply@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 51d230e0:

Fixed #28675 -- Removed always True variable in SQLInsertCompiler.execute_sql() check.

Unused since 7deb25b8dd5aa1ed02b5e30cbc67cd1fb0c3d6e6.

Note: See TracTickets for help on using tickets.
Back to Top