django/django

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

Summary

Maintainability
F
2 wks
Test Coverage

File base.py has 1478 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import inspect
import warnings
from functools import partialmethod
from itertools import chain
Severity: Major
Found in django/db/models/base.py - About 3 days to fix

    Function __new__ has a Cognitive Complexity of 127 (exceeds 5 allowed). Consider refactoring.
    Open

        def __new__(cls, name, bases, attrs, **kwargs):
            super_new = super().__new__
    
            # Also ensure initialization is only performed for subclasses of Model
            # (excluding Model class itself).
    Severity: Minor
    Found in django/db/models/base.py - About 2 days 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 61 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, *args, **kwargs):
            # Alias some things as locals to avoid repeat global lookups
            cls = self.__class__
            opts = self._meta
            _setattr = setattr
    Severity: Minor
    Found in django/db/models/base.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 save has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

        def save(self, force_insert=False, force_update=False, using=None,
                 update_fields=None):
            """
            Save the current instance. Override this in a subclass if you want to
            control the saving process.
    Severity: Minor
    Found in django/db/models/base.py - About 6 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_unique_checks has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_unique_checks(self, exclude=None):
            """
            Return a list of checks to perform. Since validate_unique() could be
            called from a ModelForm, some fields may have been excluded; we can't
            perform a unique check on a model that is missing fields involved
    Severity: Minor
    Found in django/db/models/base.py - About 5 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_ordering has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_ordering(cls):
            """
            Check "ordering" option -- is it a list of strings and do all fields
            exist?
            """
    Severity: Minor
    Found in django/db/models/base.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

    Model has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Model(metaclass=ModelBase):
    
        def __init__(self, *args, **kwargs):
            # Alias some things as locals to avoid repeat global lookups
            cls = self.__class__
    Severity: Minor
    Found in django/db/models/base.py - About 4 hrs to fix

      Function _check_long_column_names has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_long_column_names(cls):
              """
              Check that any auto-generated column names are shorter than the limits
              for each database in which the model will be created.
              """
      Severity: Minor
      Found in django/db/models/base.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 _save_table has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          def _save_table(self, raw=False, cls=None, force_insert=False,
                          force_update=False, using=None, update_fields=None):
              """
              Do the heavy-lifting involved in saving. Update or insert the data
              for a single table.
      Severity: Minor
      Found in django/db/models/base.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 refresh_from_db has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def refresh_from_db(self, using=None, fields=None):
              """
              Reload field values from the database.
      
              By default, the reloading happens from the database this instance was
      Severity: Minor
      Found in django/db/models/base.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 _perform_unique_checks has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def _perform_unique_checks(self, unique_checks):
              errors = {}
      
              for model_class, unique_check in unique_checks:
                  # Try to look up an existing object with the same values as this
      Severity: Minor
      Found in django/db/models/base.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_field_name_clashes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_field_name_clashes(cls):
              """Forbid field shadowing in multi-table inheritance."""
              errors = []
              used_fields = {}  # name or attname -> field
      
      
      Severity: Minor
      Found in django/db/models/base.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 full_clean has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def full_clean(self, exclude=None, validate_unique=True):
              """
              Call clean_fields(), clean(), and validate_unique() on the model.
              Raise a ValidationError for any errors that occur.
              """
      Severity: Minor
      Found in django/db/models/base.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 _prepare has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _prepare(cls):
              """Create some methods once self._meta has been populated."""
              opts = cls._meta
              opts._prepare(cls)
      
      
      Severity: Minor
      Found in django/db/models/base.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 _save_parents has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _save_parents(self, cls, using, update_fields):
              """Save all the parents of cls using values from self."""
              meta = cls._meta
              inserted = False
              for parent, field in meta.parents.items():
      Severity: Minor
      Found in django/db/models/base.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 _perform_date_checks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _perform_date_checks(self, date_checks):
              errors = {}
              for model_class, lookup_type, field, unique_for in date_checks:
                  lookup_kwargs = {}
                  # there's a ticket to add a date lookup, we can remove this special
      Severity: Minor
      Found in django/db/models/base.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_local_fields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_local_fields(cls, fields, option):
              from django.db import models
      
              # In order to avoid hitting the relation tree prematurely, we use our
              # own fields_map instead of using get_field()
      Severity: Minor
      Found in django/db/models/base.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 __new__ has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __new__(cls, name, bases, attrs, **kwargs):
              super_new = super().__new__
      
              # Also ensure initialization is only performed for subclasses of Model
              # (excluding Model class itself).
      Severity: Minor
      Found in django/db/models/base.py - About 1 hr to fix

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

            def save_base(self, raw=False, force_insert=False,
                          force_update=False, using=None, update_fields=None):
                """
                Handle the parts of saving which should be done only once per save,
                yet need to be done in raw saves, too. This includes some sanity
        Severity: Minor
        Found in django/db/models/base.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 clean_fields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def clean_fields(self, exclude=None):
                """
                Clean all fields and raise a ValidationError containing a dict
                of all validation errors if any occur.
                """
        Severity: Minor
        Found in django/db/models/base.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 _do_update has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
        Severity: Minor
        Found in django/db/models/base.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if field.one_to_one:
                                      for parent, parent_link in base_parents.items():
                                          if field == parent_link:
                                              base_parents[parent] = new_field
          
          
          Severity: Major
          Found in django/db/models/base.py - About 45 mins to fix

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

                def _save_table(self, raw=False, cls=None, force_insert=False,
            Severity: Minor
            Found in django/db/models/base.py - About 45 mins to fix

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

                  def _check_constraints(cls):
                      errors = []
                      for db in settings.DATABASES:
                          if not router.allow_migrate_model(db, cls):
                              continue
              Severity: Minor
              Found in django/db/models/base.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 _do_insert has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def _do_insert(self, manager, using, fields, returning_fields, raw):
              Severity: Minor
              Found in django/db/models/base.py - About 35 mins to fix

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

                    def save_base(self, raw=False, force_insert=False,
                Severity: Minor
                Found in django/db/models/base.py - About 35 mins to fix

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

                      def _check_indexes(cls):
                          """Check the fields and names of indexes."""
                          errors = []
                          for index in cls._meta.indexes:
                              # Index name can't start with an underscore or a number, restricted
                  Severity: Minor
                  Found in django/db/models/base.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 _do_update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
                          """
                          Try to update the model. Return True if the model was updated (if an
                          update query was done and a matching row was found in the DB).
                          """
                  Severity: Minor
                  Found in django/db/models/base.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