django/django

View on GitHub

Showing 2,094 of 2,094 total issues

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

                        if len(args) > 1:
                            self.feed("%s: %s" % (key_string, args[0]))
                            for arg in args[1:-1]:
                                self.feed(arg)
                            self.feed("%s," % args[-1])
Severity: Major
Found in django/db/migrations/writer.py and 1 other location - About 6 hrs to fix
django/db/migrations/writer.py on lines 65..71

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

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 len(args) > 1:
                    self.feed("%s=%s" % (_arg_name, args[0]))
                    for arg in args[1:-1]:
                        self.feed(arg)
                    self.feed("%s," % args[-1])
Severity: Major
Found in django/db/migrations/writer.py and 1 other location - About 6 hrs to fix
django/db/migrations/writer.py on lines 36..42

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

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 source.py has 423 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import os
import sys
import uuid
from ctypes import (
Severity: Minor
Found in django/contrib/gis/gdal/raster/source.py - About 6 hrs to fix

    Function init has 153 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            init: function(field_id, field_name, is_stacked) {
                if (field_id.match(/__prefix__/)) {
                    // Don't initialize on empty forms.
                    return;
                }
    Severity: Major
    Found in django/contrib/admin/static/admin/js/SelectFilter2.js - About 6 hrs to fix

      Function formset has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

          $.fn.formset = function(opts) {
              const options = $.extend({}, $.fn.formset.defaults, opts);
              const $this = $(this);
              const $parent = $this.parent();
              const updateElementIndex = function(el, prefix, ndx) {
      Severity: Minor
      Found in django/contrib/admin/static/admin/js/inlines.js - 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 condition has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

      def condition(etag_func=None, last_modified_func=None):
          """
          Decorator to support conditional retrieval (or change) for a view
          function.
      
      
      Severity: Minor
      Found in django/views/decorators/http.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 shortcut has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

      def shortcut(request, content_type_id, object_id):
          """
          Redirect to an object's page based on a content-type ID and an object ID.
          """
          # Look up the object, making sure it's got a get_absolute_url() function.
      Severity: Minor
      Found in django/contrib/contenttypes/views.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 add_georss_element has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

          def add_georss_element(self, handler, item, w3c_geo=False):
              """Add a GeoRSS XML element using the given item and handler."""
              # Getting the Geometry object.
              geom = item.get("geometry")
              if geom is not None:
      Severity: Minor
      Found in django/contrib/gis/feeds.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 __init__ has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, ds_input, write=False):
              self._write = 1 if write else 0
              Driver.ensure_registered()
      
              # Preprocess json inputs. This converts json strings to dictionaries,
      Severity: Minor
      Found in django/contrib/gis/gdal/raster/source.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 storage.py has 419 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import json
      import os
      import posixpath
      import re
      from hashlib import md5
      Severity: Minor
      Found in django/contrib/staticfiles/storage.py - About 6 hrs to fix

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

        import logging
        import string
        from datetime import datetime, timedelta
        
        from asgiref.sync import sync_to_async
        Severity: Minor
        Found in django/contrib/sessions/backends/base.py - About 6 hrs to fix

          Function format has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
          Open

          def format(
              number,
              decimal_sep,
              decimal_pos=None,
              grouping=0,
          Severity: Minor
          Found in django/utils/numberformat.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 handle has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle(self, **options):
                  db = options["database"]
                  include_stale_apps = options["include_stale_apps"]
                  interactive = options["interactive"]
                  verbosity = options["verbosity"]

          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 show_list has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
          Open

              def show_list(self, connection, app_names=None):
                  """
                  Show a list of all migrations on the system, or only those of
                  some named apps.
                  """
          Severity: Minor
          Found in django/core/management/commands/showmigrations.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_all_models has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
          Open

          def check_all_models(app_configs=None, **kwargs):
              db_table_models = defaultdict(list)
              indexes = defaultdict(list)
              constraints = defaultdict(list)
              errors = []
          Severity: Minor
          Found in django/core/checks/model_checks.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

          File creation.py has 413 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import sys
          
          from django.conf import settings
          from django.db import DatabaseError
          from django.db.backends.base.creation import BaseDatabaseCreation
          Severity: Minor
          Found in django/db/backends/oracle/creation.py - About 5 hrs to fix

            File deletion.py has 411 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            from collections import Counter, defaultdict
            from functools import partial, reduce
            from itertools import chain
            from operator import attrgetter, or_
            
            
            Severity: Minor
            Found in django/db/models/deletion.py - About 5 hrs to fix

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

              class GeoRSSFeed(Rss201rev2Feed, GeoFeedMixin):
                  def rss_attributes(self):
                      attrs = super().rss_attributes()
                      attrs["xmlns:georss"] = "http://www.georss.org/georss"
                      return attrs
              Severity: Major
              Found in django/contrib/gis/feeds.py and 1 other location - About 5 hrs to fix
              django/contrib/gis/feeds.py on lines 106..118

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

              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

              class GeoAtom1Feed(Atom1Feed, GeoFeedMixin):
                  def root_attributes(self):
                      attrs = super().root_attributes()
                      attrs["xmlns:georss"] = "http://www.georss.org/georss"
                      return attrs
              Severity: Major
              Found in django/contrib/gis/feeds.py and 1 other location - About 5 hrs to fix
              django/contrib/gis/feeds.py on lines 91..103

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

              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 message.py has 408 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import mimetypes
              from email import charset as Charset
              from email import encoders as Encoders
              from email import generator, message_from_string
              from email.errors import HeaderParseError
              Severity: Minor
              Found in django/core/mail/message.py - About 5 hrs to fix
                Severity
                Category
                Status
                Source
                Language