django/django

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

Summary

Maintainability
F
5 days
Test Coverage

File options.py has 642 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import inspect
from bisect import bisect
from collections import defaultdict

Severity: Major
Found in django/db/models/options.py - About 1 day to fix

    Options has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Options:
        FORWARD_PROPERTIES = {
            'fields', 'many_to_many', 'concrete_fields', 'local_concrete_fields',
            '_forward_fields_map', 'managers', 'managers_map', 'base_manager',
            'default_manager',
    Severity: Minor
    Found in django/db/models/options.py - About 5 hrs to fix

      Function _get_fields has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_fields(self, forward=True, reverse=True, include_parents=True, include_hidden=False,
                          seen_models=None):
              """
              Internal helper function to return fields of the model.
              * If forward=True, then fields defined on this model are returned.
      Severity: Minor
      Found in django/db/models/options.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 contribute_to_class has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          def contribute_to_class(self, cls, name):
              from django.db import connection
              from django.db.backends.utils import truncate_name
      
              cls._meta = self
      Severity: Minor
      Found in django/db/models/options.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 _prepare has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def _prepare(self, model):
              if self.order_with_respect_to:
                  # The app registry will not be ready at this point, so we cannot
                  # use get_field().
                  query = self.order_with_respect_to
      Severity: Minor
      Found in django/db/models/options.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 __init__ has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, meta, app_label=None):
              self._get_fields_cache = {}
              self.local_fields = []
              self.local_many_to_many = []
              self.private_fields = []
      Severity: Minor
      Found in django/db/models/options.py - About 1 hr to fix

        Function base_manager has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def base_manager(self):
                base_manager_name = self.base_manager_name
                if not base_manager_name:
                    # Get the first parent's base_manager_name if there's one.
                    for parent in self.model.mro()[1:]:
        Severity: Minor
        Found in django/db/models/options.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 _expire_cache has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def _expire_cache(self, forward=True, reverse=True):
                # This method is usually called by apps.cache_clear(), when the
                # registry is finalized, or when a new field is added.
                if forward:
                    for cache_key in self.FORWARD_PROPERTIES:
        Severity: Minor
        Found in django/db/models/options.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 default_manager has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def default_manager(self):
                default_manager_name = self.default_manager_name
                if not default_manager_name and not self.local_managers:
                    # Get the first parent's default_manager_name if there's one.
                    for parent in self.model.mro()[1:]:
        Severity: Minor
        Found in django/db/models/options.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 _populate_directed_relation_graph has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def _populate_directed_relation_graph(self):
                """
                This method is used by each model to find its reverse objects. As this
                method is very expensive and is accessed frequently (it looks up every
                field in a model, in every app), it is computed on first access and then
        Severity: Minor
        Found in django/db/models/options.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 swapped has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def swapped(self):
                """
                Has this model been swapped out for another? If so, return the model
                name of the replacement; otherwise, return None.
        
        
        Severity: Minor
        Found in django/db/models/options.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 add_field has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def add_field(self, field, private=False):
                # Insert the given field in the order in which it was created, using
                # the "creation_counter" attribute of the field.
                # Move many-to-many related fields from self.fields into
                # self.many_to_many.
        Severity: Minor
        Found in django/db/models/options.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_fields has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _get_fields(self, forward=True, reverse=True, include_parents=True, include_hidden=False,
        Severity: Minor
        Found in django/db/models/options.py - About 35 mins to fix

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

              def managers(self):
                  managers = []
                  seen_managers = set()
                  bases = (b for b in self.model.mro() if hasattr(b, '_meta'))
                  for depth, base in enumerate(bases):
          Severity: Minor
          Found in django/db/models/options.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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                  for field in fields:
                      res[field.name] = field
                      # Due to the way Django's internals work, get_field() should also
                      # be able to fetch a field by attname. In the case of a concrete
                      # field with relation, includes the *_id name too
          Severity: Major
          Found in django/db/models/options.py and 1 other location - About 1 hr to fix
          django/db/models/options.py on lines 534..541

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 40.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  if default_manager_name:
                      try:
                          return self.managers_map[default_manager_name]
                      except KeyError:
                          raise ValueError(
          Severity: Major
          Found in django/db/models/options.py and 1 other location - About 1 hr to fix
          django/db/models/options.py on lines 398..405

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 40.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  if base_manager_name:
                      try:
                          return self.managers_map[base_manager_name]
                      except KeyError:
                          raise ValueError(
          Severity: Major
          Found in django/db/models/options.py and 1 other location - About 1 hr to fix
          django/db/models/options.py on lines 425..432

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 40.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                  for field in fields:
                      res[field.name] = field
                      # Due to the way Django's internals work, get_field() should also
                      # be able to fetch a field by attname. In the case of a concrete
                      # field with relation, includes the *_id name too
          Severity: Major
          Found in django/db/models/options.py and 1 other location - About 1 hr to fix
          django/db/models/options.py on lines 549..556

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 40.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              @cached_property
              def local_concrete_fields(self):
                  """
                  Return a list of all concrete fields on the model.
          
          
          Severity: Minor
          Found in django/db/models/options.py and 1 other location - About 35 mins to fix
          django/db/models/options.py on lines 473..483

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 33.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              @cached_property
              def concrete_fields(self):
                  """
                  Return a list of all concrete fields on the model and its parents.
          
          
          Severity: Minor
          Found in django/db/models/options.py and 1 other location - About 35 mins to fix
          django/db/models/options.py on lines 486..496

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 33.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status