django/django

View on GitHub
django/db/models/expressions.py

Summary

Maintainability
F
5 days
Test Coverage

File expressions.py has 1023 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import datetime
import inspect
from decimal import Decimal

Severity: Major
Found in django/db/models/expressions.py - About 2 days to fix

    BaseExpression has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BaseExpression:
        """Base class for all query expressions."""
    
        # aggregate specific fields
        is_summary = False
    Severity: Minor
    Found in django/db/models/expressions.py - About 3 hrs to fix

      Combinable has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Combinable:
          """
          Provide the ability to combine one or two objects with
          some connector. For example F('foo') + F('bar').
          """
      Severity: Minor
      Found in django/db/models/expressions.py - About 2 hrs to fix

        Function convert_value has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def convert_value(self):
                """
                Expressions provide their own converters because users have the option
                of manually specifying the output_field which may be a different type
                from the one the database returns.
        Severity: Minor
        Found in django/db/models/expressions.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 identity has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def identity(self):
                constructor_signature = inspect.signature(self.__init__)
                args, kwargs = self._constructor_args
                signature = constructor_signature.bind_partial(*args, **kwargs)
                signature.apply_defaults()
        Severity: Minor
        Found in django/db/models/expressions.py - About 55 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 as_sql has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def as_sql(self, compiler, connection):
                try:
                    lhs_output = self.lhs.output_field
                except FieldError:
                    lhs_output = None
        Severity: Minor
        Found in django/db/models/expressions.py - About 55 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 resolve_expression has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def resolve_expression(self, query=None, allow_joins=True, reuse=None,
        Severity: Minor
        Found in django/db/models/expressions.py - About 45 mins to fix

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

              def resolve_expression(self, query=None, allow_joins=True, reuse=None,
          Severity: Minor
          Found in django/db/models/expressions.py - About 45 mins to fix

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

                def as_sql(self, compiler, connection, function=None, template=None, arg_joiner=None, **extra_context):
            Severity: Minor
            Found in django/db/models/expressions.py - About 45 mins to fix

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

                  def __init__(self, expression, partition_by=None, order_by=None, frame=None, output_field=None):
                      self.partition_by = partition_by
                      self.order_by = order_by
                      self.frame = frame
              
              
              Severity: Minor
              Found in django/db/models/expressions.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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def __init__(self, expression, partition_by=None, order_by=None, frame=None, output_field=None):
              Severity: Minor
              Found in django/db/models/expressions.py - About 35 mins to fix

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

                    def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                Severity: Minor
                Found in django/db/models/expressions.py - About 35 mins to fix

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

                      def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                  Severity: Minor
                  Found in django/db/models/expressions.py - About 35 mins to fix

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

                        def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                    Severity: Minor
                    Found in django/db/models/expressions.py - About 35 mins to fix

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

                          def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                      Severity: Minor
                      Found in django/db/models/expressions.py - About 35 mins to fix

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

                            def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                        Severity: Minor
                        Found in django/db/models/expressions.py - About 35 mins to fix

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

                              def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                          Severity: Minor
                          Found in django/db/models/expressions.py - About 35 mins to fix

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

                                def as_sql(self, compiler, connection, template=None, case_joiner=None, **extra_context):
                            Severity: Minor
                            Found in django/db/models/expressions.py - About 35 mins to fix

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

                                  def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                              Severity: Minor
                              Found in django/db/models/expressions.py - About 35 mins to fix

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

                                    def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                                Severity: Minor
                                Found in django/db/models/expressions.py - About 35 mins to fix

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

                                      def __str__(self):
                                          if self.start.value is not None and self.start.value < 0:
                                              start = '%d %s' % (abs(self.start.value), connection.ops.PRECEDING)
                                          elif self.start.value is not None and self.start.value == 0:
                                              start = connection.ops.CURRENT_ROW
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 as_sql has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def as_sql(self, compiler, connection):
                                          connection.ops.check_expression_support(self)
                                          val = self.value
                                          output_field = self._output_field_or_none
                                          if output_field is not None:
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 as_sql has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def as_sql(self, compiler, connection, template=None, **extra_context):
                                          if not template:
                                              if self.nulls_last:
                                                  template = '%s NULLS LAST' % self.template
                                              elif self.nulls_first:
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def __init__(self, condition=None, then=None, **lookups):
                                          if lookups and condition is None:
                                              condition, lookups = Q(**lookups), None
                                          if condition is None or not getattr(condition, 'conditional', False) or lookups:
                                              raise TypeError("__init__() takes either a Q object or lookups as keyword arguments")
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 _resolve_output_field has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def _resolve_output_field(self):
                                          """
                                          Attempt to infer the output type of the expression. If the output
                                          fields of all source fields match then, simply infer the same type
                                          here. This isn't always correct, but it makes sense most of the time.
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 compile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def compile(self, side, compiler, connection):
                                          if not isinstance(side, DurationValue):
                                              try:
                                                  output = side.output_field
                                              except FieldError:
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 as_sql has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def as_sql(self, compiler, connection, template=None, case_joiner=None, **extra_context):
                                          connection.ops.check_expression_support(self)
                                          if not self.cases:
                                              return compiler.compile(self.default)
                                          template_params = {**self.extra, **extra_context}
                                  Severity: Minor
                                  Found in django/db/models/expressions.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 resolve_expression has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
                                          # Resolve parents fields used in raw SQL.
                                          for parent in query.model._meta.get_parent_list():
                                              for parent_field in parent._meta.local_fields:
                                                  _, column_name = parent_field.get_attname_column()
                                  Severity: Minor
                                  Found in django/db/models/expressions.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