#28675: Tautology in sql/compiler/SQLInsertCompiler.execute_sql()
------------------------------------------+------------------------
               Reporter:  Дилян Палаузов  |          Owner:  nobody
                   Type:  Uncategorized   |         Status:  new
              Component:  Uncategorized   |        Version:  1.11
               Severity:  Normal          |       Keywords:
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+------------------------
 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
              )

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28675>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/057.5386e8bd1c7f5f0f412900743a1b1d11%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to