django/django

View on GitHub

Showing 2,094 of 2,094 total issues

Function _changeform_view has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    def _changeform_view(self, request, object_id, form_url, extra_context):
        to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
        if to_field and not self.to_field_allowed(request, to_field):
            raise DisallowedModelAdminToField(
                "The field %s cannot be referenced." % to_field
Severity: Minor
Found in django/contrib/admin/options.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

File migrate.py has 453 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import sys
import time
from importlib import import_module

from django.apps import apps
Severity: Minor
Found in django/core/management/commands/migrate.py - About 6 hrs to fix

    MigrationAutodetector has 49 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MigrationAutodetector:
        """
        Take a pair of ProjectStates and compare them to see what the first would
        need doing to make it match the second (the second usually being the
        project's current state).
    Severity: Minor
    Found in django/db/migrations/autodetector.py - About 6 hrs to fix

      File functions.py has 451 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      from decimal import Decimal
      
      from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
      from django.contrib.gis.db.models.sql import AreaField, DistanceField
      from django.contrib.gis.geos import GEOSGeometry
      Severity: Minor
      Found in django/contrib/gis/db/models/functions.py - About 6 hrs to fix

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

        """
        Oracle database backend for Django.
        
        Requires oracledb: https://oracle.github.io/python-oracledb/
        """
        Severity: Minor
        Found in django/db/backends/oracle/base.py - About 6 hrs to fix

          Function generate_altered_fields has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
          Open

              def generate_altered_fields(self):
                  """
                  Make AlterField operations, or possibly RemovedField/AddField if alter
                  isn't possible.
                  """
          Severity: Minor
          Found in django/db/migrations/autodetector.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 handle has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle(self, *app_labels, **options):
                  self.written_files = []
                  self.verbosity = options["verbosity"]
                  self.interactive = options["interactive"]
                  self.dry_run = options["dry_run"]
          Severity: Minor
          Found in django/core/management/commands/makemigrations.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 fields_for_model has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

          def fields_for_model(
              model,
              fields=None,
              exclude=None,
              widgets=None,
          Severity: Minor
          Found in django/forms/models.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 changelist_view has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

              def changelist_view(self, request, extra_context=None):
                  """
                  The 'change list' admin view for this model.
                  """
                  from django.contrib.admin.views.main import ERROR_FLAG
          Severity: Minor
          Found in django/contrib/admin/options.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 _ogrinspect has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

          def _ogrinspect(
              data_source,
              model_name,
              geom_name="geom",
              layer_key=0,
          Severity: Minor
          Found in django/contrib/gis/utils/ogrinspect.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 serialize has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

              def serialize(
                  self,
                  queryset,
                  *,
                  stream=None,
          Severity: Minor
          Found in django/core/serializers/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

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

              for index_name, model_labels in indexes.items():
                  if len(model_labels) > 1:
                      model_labels = set(model_labels)
                      errors.append(
                          Error(
          Severity: Major
          Found in django/core/checks/model_checks.py and 1 other location - About 6 hrs to fix
          django/core/checks/model_checks.py on lines 76..87

          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 105.

          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

              for constraint_name, model_labels in constraints.items():
                  if len(model_labels) > 1:
                      model_labels = set(model_labels)
                      errors.append(
                          Error(
          Severity: Major
          Found in django/core/checks/model_checks.py and 1 other location - About 6 hrs to fix
          django/core/checks/model_checks.py on lines 62..73

          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 105.

          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

          File makemigrations.py has 440 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import os
          import sys
          import warnings
          from itertools import takewhile
          
          
          Severity: Minor
          Found in django/core/management/commands/makemigrations.py - About 6 hrs to fix

            Function run has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
            Open

                def run(self):
                    def args_to_win(cmdline):
                        changed = False
                        out = []
                        for token in cmdline.split():
            Severity: Minor
            Found in docs/_ext/djangodocs.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

            Consider simplifying this complex logical expression.
            Open

                    if (
                        dependency.field_name is None
                        and dependency.type == OperationDependency.Type.CREATE
                    ):
                        return (
            Severity: Critical
            Found in django/db/migrations/autodetector.py - About 6 hrs to fix

              File views.py has 428 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import inspect
              from importlib import import_module
              from inspect import cleandoc
              from pathlib import Path
              
              
              Severity: Minor
              Found in django/contrib/admindocs/views.py - About 6 hrs to fix

                Function watched_roots has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                Open

                    def watched_roots(self, watched_files):
                        extra_directories = self.directory_globs.keys()
                        watched_file_dirs = [f.parent for f in watched_files]
                        sys_paths = list(sys_path_directories())
                        return frozenset((*extra_directories, *watched_file_dirs, *sys_paths))
                Severity: Minor
                Found in django/utils/autoreload.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 label_for_field has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                Open

                def label_for_field(name, model, model_admin=None, return_attr=False, form=None):
                    """
                    Return a sensible label for a field name. The name can be a callable,
                    property (but not created with @property decorator), or the name of an
                    object's attribute, as well as a model field, including across related
                Severity: Minor
                Found in django/contrib/admin/utils.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 handle has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                Open

                    def handle(self, *args, **options):
                        locale = options["locale"]
                        exclude = options["exclude"]
                        self.domain = options["domain"]
                        self.verbosity = options["verbosity"]
                Severity: Minor
                Found in django/core/management/commands/makemessages.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

                Severity
                Category
                Status
                Source
                Language