django/django

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

Summary

Maintainability
F
1 wk
Test Coverage

File related.py has 1336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import functools
import inspect
from functools import partial

from django import forms
Severity: Major
Found in django/db/models/fields/related.py - About 3 days to fix

    Function _check_relationship_model has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_relationship_model(self, from_model=None, **kwargs):
            if hasattr(self.remote_field.through, '_meta'):
                qualified_model_name = "%s.%s" % (
                    self.remote_field.through._meta.app_label, self.remote_field.through.__name__)
            else:
    Severity: Minor
    Found in django/db/models/fields/related.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

    ForeignObject has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ForeignObject(RelatedField):
        """
        Abstraction of the ForeignKey relation to support multi-column relations.
        """
    
    
    Severity: Minor
    Found in django/db/models/fields/related.py - About 2 hrs to fix

      ForeignKey has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class ForeignKey(ForeignObject):
          """
          Provide a many-to-one relation by adding a column to the local model
          to hold the remote value.
      
      
      Severity: Minor
      Found in django/db/models/fields/related.py - About 2 hrs to fix

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

        class ManyToManyField(RelatedField):
            """
            Provide a many-to-many relation by using an intermediary model that
            holds two ForeignKey fields pointed at the two sides of the relation.
        
        
        Severity: Minor
        Found in django/db/models/fields/related.py - About 2 hrs to fix

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

              def _get_m2m_reverse_attr(self, related, attr):
                  """
                  Function that can be curried to provide the related accessor or DB
                  column name for the m2m table.
                  """
          Severity: Minor
          Found in django/db/models/fields/related.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 _check_table_uniqueness has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              def _check_table_uniqueness(self, **kwargs):
                  if isinstance(self.remote_field.through, str) or not self.remote_field.through._meta.managed:
                      return []
                  registered_tables = {
                      model._meta.db_table: model
          Severity: Minor
          Found in django/db/models/fields/related.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 deconstruct has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def deconstruct(self):
                  name, path, args, kwargs = super().deconstruct()
                  # Handle the simpler arguments.
                  if self.db_table is not None:
                      kwargs['db_table'] = self.db_table
          Severity: Minor
          Found in django/db/models/fields/related.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 _check_clashes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def _check_clashes(self):
                  """Check accessor and reverse query name clashes."""
                  from django.db.models.base import ModelBase
          
                  errors = []
          Severity: Minor
          Found in django/db/models/fields/related.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 __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, to, on_delete, from_fields, to_fields, rel=None, related_name=None,
          Severity: Major
          Found in django/db/models/fields/related.py - About 1 hr to fix

            Function __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(self, to, related_name=None, related_query_name=None,
            Severity: Major
            Found in django/db/models/fields/related.py - About 1 hr to fix

              Function __init__ has 9 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def __init__(self, to, on_delete, related_name=None, related_query_name=None,
              Severity: Major
              Found in django/db/models/fields/related.py - About 1 hr to fix

                Function deconstruct has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def deconstruct(self):
                        name, path, args, kwargs = super().deconstruct()
                        kwargs['on_delete'] = self.remote_field.on_delete
                        kwargs['from_fields'] = self.from_fields
                        kwargs['to_fields'] = self.to_fields
                Severity: Minor
                Found in django/db/models/fields/related.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 contribute_to_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def contribute_to_class(self, cls, name, private_only=False, **kwargs):
                
                        super().contribute_to_class(cls, name, private_only=private_only, **kwargs)
                
                        self.opts = cls._meta
                Severity: Minor
                Found in django/db/models/fields/related.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_related_fields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def resolve_related_fields(self):
                        if not self.from_fields or len(self.from_fields) != len(self.to_fields):
                            raise ValueError('Foreign Object from and to fields must be the same non-zero length')
                        if isinstance(self.remote_field.model, str):
                            raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
                Severity: Minor
                Found in django/db/models/fields/related.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 contribute_to_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def contribute_to_class(self, cls, name, **kwargs):
                        # To support multiple relations to self, it's useful to have a non-None
                        # related name on symmetrical relations for internal reasons. The
                        # concept doesn't make a lot of sense externally ("you want me to
                        # specify *what* on my non-reversible relation?!"), so we set it up
                Severity: Minor
                Found in django/db/models/fields/related.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_m2m_attr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _get_m2m_attr(self, related, attr):
                        """
                        Function that can be curried to provide the source accessor or DB
                        column name for the m2m table.
                        """
                Severity: Minor
                Found in django/db/models/fields/related.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

                Avoid deeply nested control flow statements.
                Open

                                        if hasattr(f, 'remote_field') and getattr(f.remote_field, 'model', None) == related_model:
                                            possible_field_names.append(f.name)
                                    if possible_field_names:
                Severity: Major
                Found in django/db/models/fields/related.py - About 45 mins to fix

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

                      def _check_to_fields_exist(self):
                          # Skip nonexistent models.
                          if isinstance(self.remote_field.model, str):
                              return []
                  
                  
                  Severity: Minor
                  Found in django/db/models/fields/related.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 _check_unique_target has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def _check_unique_target(self):
                          rel_is_string = isinstance(self.remote_field.model, str)
                          if rel_is_string or not self.requires_unique_target:
                              return []
                  
                  
                  Severity: Minor
                  Found in django/db/models/fields/related.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_instance_value_for_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_instance_value_for_fields(instance, fields):
                          ret = []
                          opts = instance._meta
                          for field in fields:
                              # Gotcha: in some cases (like fixture loading) a model can have
                  Severity: Minor
                  Found in django/db/models/fields/related.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/fields/related.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return [
                    Severity: Major
                    Found in django/db/models/fields/related.py - About 30 mins to fix

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

                          def deconstruct(self):
                              name, path, args, kwargs = super().deconstruct()
                              del kwargs['to_fields']
                              del kwargs['from_fields']
                              # Handle the simpler arguments
                      Severity: Minor
                      Found in django/db/models/fields/related.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 get_col has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def get_col(self, alias, output_field=None):
                              if output_field is None:
                                  output_field = self.target_field
                                  while isinstance(output_field, ForeignKey):
                                      output_field = output_field.target_field
                      Severity: Minor
                      Found in django/db/models/fields/related.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