django/django

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

Summary

Maintainability
F
1 wk
Test Coverage

File __init__.py has 2383 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import datetime
import decimal
import operator
import uuid
Severity: Major
Found in django/db/models/fields/__init__.py - About 6 days to fix

    Function _check_choices has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_choices(self):
            if not self.choices:
                return []
    
            if not isinstance(self.choices, Iterable) or isinstance(self.choices, str):
    Severity: Minor
    Found in django/db/models/fields/__init__.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 __init__ has 24 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in django/db/models/fields/__init__.py - About 3 hrs to fix

      Function validate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate(self, value, model_instance):
              """
              Validate value and raise ValidationError if necessary. Subclasses
              should override this to provide validation logic.
              """
      Severity: Minor
      Found in django/db/models/fields/__init__.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 formfield has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def formfield(self, form_class=None, choices_form_class=None, **kwargs):
              """Return a django.forms.Field instance for this field."""
              defaults = {
                  "required": not self.blank,
                  "label": capfirst(self.verbose_name),
      Severity: Minor
      Found in django/db/models/fields/__init__.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 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def deconstruct(self):
              """
              Return enough information to recreate the field as a 4-tuple:
      
               * The name of the field on the model, if contribute_to_class() has
      Severity: Minor
      Found in django/db/models/fields/__init__.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 to_python has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_python(self, value):
              if value is None:
                  return value
              if isinstance(value, datetime.datetime):
                  return value
      Severity: Minor
      Found in django/db/models/fields/__init__.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_db_default has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_db_default(self, databases=None, **kwargs):
              from django.db.models.expressions import Value
      
              if (
                  self.db_default is NOT_PROVIDED
      Severity: Minor
      Found in django/db/models/fields/__init__.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 validators has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def validators(self):
              # These validators can't be added at field initialization time since
              # they're based on values retrieved from `connection`.
              validators_ = super().validators
              internal_type = self.get_internal_type()
      Severity: Minor
      Found in django/db/models/fields/__init__.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 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(
      Severity: Major
      Found in django/db/models/fields/__init__.py - About 1 hr to fix

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

            def run_validators(self, value):
                if value in self.empty_values:
                    return
        
                errors = []
        Severity: Minor
        Found in django/db/models/fields/__init__.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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Major
        Found in django/db/models/fields/__init__.py - About 50 mins to fix

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

              def __init__(
          Severity: Minor
          Found in django/db/models/fields/__init__.py - About 45 mins to fix

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

                def to_python(self, value):
                    if value is None:
                        return value
                    if isinstance(value, datetime.datetime):
                        if settings.USE_TZ and timezone.is_aware(value):
            Severity: Minor
            Found in django/db/models/fields/__init__.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(
            Severity: Minor
            Found in django/db/models/fields/__init__.py - About 45 mins to fix

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

                  def __init__(
              Severity: Minor
              Found in django/db/models/fields/__init__.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if value == optgroup_key:
                                            return
                                elif value == option_key:
                Severity: Major
                Found in django/db/models/fields/__init__.py - About 45 mins to fix

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

                      def __init__(
                  Severity: Minor
                  Found in django/db/models/fields/__init__.py - About 45 mins to fix

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

                        def _check_db_comment(self, databases=None, **kwargs):
                            if not self.db_comment or not databases:
                                return []
                            errors = []
                            for db in databases:
                    Severity: Minor
                    Found in django/db/models/fields/__init__.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_choices has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def get_choices(
                    Severity: Minor
                    Found in django/db/models/fields/__init__.py - About 35 mins to fix

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

                          def get_choices(
                              self,
                              include_blank=True,
                              blank_choice=BLANK_CHOICE_DASH,
                              limit_choices_to=None,
                      Severity: Minor
                      Found in django/db/models/fields/__init__.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_default has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def _get_default(self):
                              if self.has_default():
                                  if callable(self.default):
                                      return self.default
                                  return lambda: self.default
                      Severity: Minor
                      Found in django/db/models/fields/__init__.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_max_length_attribute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def _check_max_length_attribute(self, **kwargs):
                              if self.max_length is None:
                                  if (
                                      connection.features.supports_unlimited_charfield
                                      or "supports_unlimited_charfield"
                      Severity: Minor
                      Found in django/db/models/fields/__init__.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 __lt__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def __lt__(self, other):
                              # This is needed because bisect does not take a comparison function.
                              # Order by creation_counter first for backward compatibility.
                              if isinstance(other, Field):
                                  if (
                      Severity: Minor
                      Found in django/db/models/fields/__init__.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 datetime.datetime(parsed.year, parsed.month, parsed.day)
                      Severity: Major
                      Found in django/db/models/fields/__init__.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

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

                          Avoid too many return statements within this function.
                          Open

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

                            Avoid too many return statements within this function.
                            Open

                                    return str  # return empty string
                            Severity: Major
                            Found in django/db/models/fields/__init__.py - About 30 mins to fix

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

                                  def to_python(self, value):
                                      if self.null and value in self.empty_values:
                                          return None
                                      if value in (True, False):
                                          # 1/0 are equal to True/False. bool() converts former to latter.
                              Severity: Minor
                              Found in django/db/models/fields/__init__.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_db_collation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  def _check_db_collation(self, databases):
                                      errors = []
                                      for db in databases:
                                          if not router.allow_migrate_model(db, self.model):
                                              continue
                              Severity: Minor
                              Found in django/db/models/fields/__init__.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 deconstruct has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  def deconstruct(self):
                                      name, path, args, kwargs = super().deconstruct()
                                      if self.path != "":
                                          kwargs["path"] = self.path
                                      if self.match is not None:
                              Severity: Minor
                              Found in django/db/models/fields/__init__.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_db_collation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  def _check_db_collation(self, databases):
                                      errors = []
                                      for db in databases:
                                          if not router.allow_migrate_model(db, self.model):
                                              continue
                              Severity: Minor
                              Found in django/db/models/fields/__init__.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