django/django

View on GitHub
django/db/models/sql/compiler.py

Summary

Maintainability
F
1 wk
Test Coverage

File compiler.py has 1300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import collections
import re
from functools import partial
from itertools import chain

Severity: Major
Found in django/db/models/sql/compiler.py - About 3 days to fix

    Function as_sql has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
    Open

        def as_sql(self, with_limits=True, with_col_aliases=False):
            """
            Create the SQL for this query. Return the SQL string and list of
            parameters.
    
    
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_order_by has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_order_by(self):
            """
            Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the
            ORDER BY clause.
    
    
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_related_selections has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_related_selections(self, select, opts=None, root_alias=None, cur_depth=1,
                                   requested=None, restricted=None):
            """
            Fill in the information needed for a select_related query. The current
            depth is measured as the number of connections away from the root model
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_select_for_update_of_arguments has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_select_for_update_of_arguments(self):
            """
            Return a quoted list of arguments for the SELECT FOR UPDATE OF part of
            the query.
            """
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 6 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_combinator_sql has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_combinator_sql(self, combinator, all):
            features = self.connection.features
            compilers = [
                query.get_compiler(self.using, self.connection)
                for query in self.query.combined_queries if not query.is_empty()
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function as_sql has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def as_sql(self):
            """
            Create the SQL for this query. Return the SQL string and list of
            parameters.
            """
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_group_by has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_group_by(self, select, order_by):
            """
            Return a list of 2-tuples of form (sql, params).
    
            The logic of what exactly the GROUP BY clause contains is hard
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_select has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_select(self):
            """
            Return three values:
            - a list of 3-tuples of (expression, (sql, params), alias)
            - a klass_info structure,
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function find_ordering_name has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def find_ordering_name(self, name, opts, alias=None, default_order='ASC',
                               already_seen=None):
            """
            Return the table alias (the name might be ambiguous, the alias will
            not be) and column name for ordering by the given 'name' parameter.
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function as_sql has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def as_sql(self):
            # We don't need quote_name_unless_alias() here, since these are all
            # going to be column names (so we can avoid the extra overhead).
            qn = self.connection.ops.quote_name
            opts = self.query.get_meta()
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function execute_sql has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def execute_sql(self, result_type=MULTI, chunked_fetch=False, chunk_size=GET_ITERATOR_CHUNK_SIZE):
            """
            Run the query against the database and return the result(s). The
            return value is a single data item if result_type is SINGLE, or an
            iterator over the results if the result_type is MULTI.
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function collapse_group_by has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def collapse_group_by(self, expressions, having):
            # If the DB can group by primary key, then group by the primary key of
            # query's main model. Note that for PostgreSQL the GROUP BY clause must
            # include the primary key of every table, but for MySQL it is enough to
            # have the main table's primary key.
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_default_columns has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_default_columns(self, start_alias=None, opts=None, from_parent=None):
            """
            Compute the default columns for selecting every field in the base
            model. Will sometimes be called to pull in related models (e.g. via
            select_related), in which case "opts" and "start_alias" will be given
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_from_clause has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_from_clause(self):
            """
            Return a list of strings that are joined together to go after the
            "FROM" part of the query, as well as a list any extra parameters that
            need to be included. Subclasses, can override this to create a
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function prepare_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def prepare_value(self, field, value):
            """
            Prepare a value to be used in a query by resolving it if it is an
            expression and otherwise calling the field's get_db_prep_save().
            """
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_related_selections has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def get_related_selections(self, select, opts=None, root_alias=None, cur_depth=1,
    Severity: Minor
    Found in django/db/models/sql/compiler.py - About 45 mins to fix

      Function results_iter has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def results_iter(self, results=None, tuple_expected=False, chunked_fetch=False,
      Severity: Minor
      Found in django/db/models/sql/compiler.py - About 35 mins to fix

        Function find_ordering_name has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def find_ordering_name(self, name, opts, alias=None, default_order='ASC',
        Severity: Minor
        Found in django/db/models/sql/compiler.py - About 35 mins to fix

          Function get_distinct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_distinct(self):
                  """
                  Return a quoted list of fields to use in DISTINCT ON part of the query.
          
                  This method can alter the tables in the query, and thus it must be
          Severity: Minor
          Found in django/db/models/sql/compiler.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_extra_select has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_extra_select(self, order_by, select):
                  extra_select = []
                  if self.query.distinct and not self.query.distinct_fields:
                      select_sql = [t[1] for t in select]
                      for expr, (sql, params, is_ref) in order_by:
          Severity: Minor
          Found in django/db/models/sql/compiler.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid too many return statements within this function.
          Open

                      return
          Severity: Major
          Found in django/db/models/sql/compiler.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return result
            Severity: Major
            Found in django/db/models/sql/compiler.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return list(result)
              Severity: Major
              Found in django/db/models/sql/compiler.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return val
                Severity: Major
                Found in django/db/models/sql/compiler.py - About 30 mins to fix

                  Function get_converters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_converters(self, expressions):
                          converters = {}
                          for i, expression in enumerate(expressions):
                              if expression:
                                  backend_converters = self.connection.ops.get_db_converters(expression)
                  Severity: Minor
                  Found in django/db/models/sql/compiler.py - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function pre_sql_setup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def pre_sql_setup(self):
                          """
                          If the update depends on results from other tables, munge the "where"
                          conditions to match the format required for (portable) SQL updates.
                  
                  
                  Severity: Minor
                  Found in django/db/models/sql/compiler.py - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function apply_converters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def apply_converters(self, rows, converters):
                          connection = self.connection
                          converters = list(converters.items())
                          for row in map(list, rows):
                              for pos, (convs, expression) in converters:
                  Severity: Minor
                  Found in django/db/models/sql/compiler.py - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  There are no issues that match your filters.

                  Category
                  Status