django/django

View on GitHub
django/core/management/commands/migrate.py

Summary

Maintainability
F
5 days
Test Coverage

Function handle has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **options):
        database = options['database']
        if not options['skip_checks']:
            self.check(databases=[database])

Severity: Minor
Found in django/core/management/commands/migrate.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 migration_progress_callback has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    def migration_progress_callback(self, action, migration=None, fake=False):
        if self.verbosity >= 1:
            compute_time = self.verbosity > 1
            if action == "apply_start":
                if compute_time:
Severity: Minor
Found in django/core/management/commands/migrate.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 migrate.py has 322 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 3 hrs to fix

    Function sync_apps has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def sync_apps(self, connection, app_labels):
            """Run the old syncdb-style operation on a list of app_labels."""
            with connection.cursor() as cursor:
                tables = connection.introspection.table_names(cursor)
    
    
    Severity: Minor
    Found in django/core/management/commands/migrate.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 describe_operation has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def describe_operation(operation, backwards):
            """Return a string that describes a migration operation for --plan."""
            prefix = ''
            is_error = False
            if hasattr(operation, 'code'):
    Severity: Minor
    Found in django/core/management/commands/migrate.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 handle has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def handle(self, *args, **options):
            database = options['database']
            if not options['skip_checks']:
                self.check(databases=[database])
    
    
    Severity: Minor
    Found in django/core/management/commands/migrate.py - About 1 hr to fix

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

                  elif action == "unapply_success":
                      elapsed = " (%.3fs)" % (time.monotonic() - self.start) if compute_time else ""
                      if fake:
                          self.stdout.write(self.style.SUCCESS(" FAKED" + elapsed))
                      else:
      Severity: Major
      Found in django/core/management/commands/migrate.py and 1 other location - About 4 hrs to fix
      django/core/management/commands/migrate.py on lines 280..285

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

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

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

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

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

      Refactorings

      Further Reading

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

                  elif action == "apply_success":
                      elapsed = " (%.3fs)" % (time.monotonic() - self.start) if compute_time else ""
                      if fake:
                          self.stdout.write(self.style.SUCCESS(" FAKED" + elapsed))
                      else:
      Severity: Major
      Found in django/core/management/commands/migrate.py and 1 other location - About 4 hrs to fix
      django/core/management/commands/migrate.py on lines 291..296

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

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

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

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

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

      Refactorings

      Further Reading

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

              if conflicts:
                  name_str = "; ".join(
                      "%s in %s" % (", ".join(names), app)
                      for app, names in conflicts.items()
                  )
      Severity: Major
      Found in django/core/management/commands/migrate.py and 1 other location - About 2 hrs to fix
      django/core/management/commands/makemigrations.py on lines 122..128

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

      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 action == "apply_start":
                      if compute_time:
                          self.start = time.monotonic()
                      self.stdout.write("  Applying %s..." % migration, ending="")
                      self.stdout.flush()
      Severity: Major
      Found in django/core/management/commands/migrate.py and 1 other location - About 1 hr to fix
      django/core/management/commands/migrate.py on lines 286..290

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

      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

                  elif action == "unapply_start":
                      if compute_time:
                          self.start = time.monotonic()
                      self.stdout.write("  Unapplying %s..." % migration, ending="")
                      self.stdout.flush()
      Severity: Major
      Found in django/core/management/commands/migrate.py and 1 other location - About 1 hr to fix
      django/core/management/commands/migrate.py on lines 275..279

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

      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 3 locations. Consider refactoring.
      Open

                      try:
                          migration = executor.loader.get_migration_by_prefix(app_label, migration_name)
                      except AmbiguityError:
                          raise CommandError(
                              "More than one migration matches '%s' in app '%s'. "
      Severity: Major
      Found in django/core/management/commands/migrate.py and 2 other locations - About 1 hr to fix
      django/core/management/commands/sqlmigrate.py on lines 48..55
      django/core/management/commands/squashmigrations.py on lines 207..217

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

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

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

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

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

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status