django/django

View on GitHub
django/db/models/fields/related_descriptors.py

Summary

Maintainability
F
6 days
Test Coverage

File related_descriptors.py has 879 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Accessors for related objects.

When a field defines a relation between two models, each model class provides
an attribute to access related instances of the other model class (unless the
Severity: Major
Found in django/db/models/fields/related_descriptors.py - About 2 days to fix

    Function create_forward_many_to_many_manager has a Cognitive Complexity of 89 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_forward_many_to_many_manager(superclass, rel, reverse):
        """
        Create a manager for the either side of a many-to-many relation.
    
        This manager subclasses another manager, generally the default manager of
    Severity: Minor
    Found in django/db/models/fields/related_descriptors.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 create_reverse_many_to_one_manager has a Cognitive Complexity of 78 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_reverse_many_to_one_manager(superclass, rel):
        """
        Create a manager for the reverse side of a many-to-one relation.
    
        This manager subclasses another manager, generally the default manager of
    Severity: Minor
    Found in django/db/models/fields/related_descriptors.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 __set__ has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def __set__(self, instance, value):
            """
            Set the related instance through the forward relation.
    
            With the example above, when setting ``child.parent = parent``:
    Severity: Minor
    Found in django/db/models/fields/related_descriptors.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__ has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def __get__(self, instance, cls=None):
            """
            Get the related instance through the forward relation.
    
            With the example above, when getting ``child.parent``:
    Severity: Minor
    Found in django/db/models/fields/related_descriptors.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 __set__ has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def __set__(self, instance, value):
            """
            Set the related instance through the reverse relation.
    
            With the example above, when setting ``place.restaurant = restaurant``:
    Severity: Minor
    Found in django/db/models/fields/related_descriptors.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 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def __get__(self, instance, cls=None):
            """
            Get the related instance through the reverse relation.
    
            With the example above, when getting ``place.restaurant``:
    Severity: Minor
    Found in django/db/models/fields/related_descriptors.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

    Avoid deeply nested control flow statements.
    Open

                                if obj in old_objs:
                                    old_objs.remove(obj)
                                else:
                                    new_objs.append(obj)
    
    
    Severity: Major
    Found in django/db/models/fields/related_descriptors.py - About 45 mins to fix

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

          def get_prefetch_queryset(self, instances, queryset=None):
              if queryset is None:
                  queryset = self.get_queryset()
              queryset._add_hints(instance=instances[0])
      
      
      Severity: Minor
      Found in django/db/models/fields/related_descriptors.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 __set__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __set__(self, instance, value):
              super().__set__(instance, value)
              # If the primary key is a link to a parent model and a parent instance
              # is being set, update the value of the inherited pk(s).
              if self.field.primary_key and self.field.remote_field.parent_link:
      Severity: Minor
      Found in django/db/models/fields/related_descriptors.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