django/django

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

Summary

Maintainability
C
1 day
Test Coverage

File query_utils.py has 383 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Various data structures used in query construction.

Factored out from django.db.models.query to avoid making the main module very
large and/or so that they can be used by other modules without getting into
Severity: Minor
Found in django/db/models/query_utils.py - About 5 hrs to fix

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

    def select_related_descend(field, restricted, requested, select_mask, reverse=False):
        """
        Return True if this field should be used to descend deeper for
        select_related() purposes. Used by both the query construction code
        (compiler.get_related_selections()) and the model instance creation code
    Severity: Minor
    Found in django/db/models/query_utils.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__ has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def __get__(self, instance, cls=None):
            """
            Retrieve and caches the value from the datastore on the first lookup.
            Return the cached value.
            """
    Severity: Minor
    Found in django/db/models/query_utils.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 resolve_expression has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def resolve_expression(
    Severity: Minor
    Found in django/db/models/query_utils.py - About 35 mins to fix

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

      def select_related_descend(field, restricted, requested, select_mask, reverse=False):
      Severity: Minor
      Found in django/db/models/query_utils.py - About 35 mins to fix

        Avoid too many return statements within this function.
        Open

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

          Avoid too many return statements within this function.
          Open

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

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

                def flatten(self):
                    """
                    Recursively yield this Q object and all subexpressions, in depth-first
                    order.
                    """
            Severity: Minor
            Found in django/db/models/query_utils.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 check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def check(self, against, using=DEFAULT_DB_ALIAS):
                    """
                    Do a database query to check if the expressions of the Q instance
                    matches against the expressions.
                    """
            Severity: Minor
            Found in django/db/models/query_utils.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