django/django

View on GitHub
django/db/migrations/loader.py

Summary

Maintainability
D
2 days
Test Coverage

Function load_disk has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    def load_disk(self):
        """Load the migrations from all INSTALLED_APPS from disk."""
        self.disk_migrations = {}
        self.unmigrated_apps = set()
        self.migrated_apps = set()
Severity: Minor
Found in django/db/migrations/loader.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

Function build_graph has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    def build_graph(self):
        """
        Build a migration dependency graph using both the disk and database.
        You'll need to rebuild the graph if you apply migrations. This isn't
        usually a problem as generally migration stuff runs in a one-shot process.
Severity: Minor
Found in django/db/migrations/loader.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

File loader.py has 282 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import pkgutil
import sys
from importlib import import_module, reload

from django.apps import apps
Severity: Minor
Found in django/db/migrations/loader.py - About 2 hrs to fix

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

        def check_consistent_history(self, connection):
            """
            Raise InconsistentMigrationHistory if any applied migrations have
            unapplied dependencies.
            """
    Severity: Minor
    Found in django/db/migrations/loader.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_key has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def check_key(self, key, current_app):
            if (key[1] != "__first__" and key[1] != "__latest__") or key in self.graph:
                return key
            # Special-case __first__, which means "the first migration" for
            # migrated apps, and is ignored for unmigrated apps. It allows
    Severity: Minor
    Found in django/db/migrations/loader.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

    Avoid deeply nested control flow statements.
    Open

                            if all(m in applied for m in self.replacements[parent].replaces):
                                continue
                        raise InconsistentMigrationHistory(
    Severity: Major
    Found in django/db/migrations/loader.py - About 45 mins to fix

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

          def add_external_dependencies(self, key, migration):
              for parent in migration.dependencies:
                  # Skip internal dependencies
                  if key[0] == parent[0]:
                      continue
      Severity: Minor
      Found in django/db/migrations/loader.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_migration_by_prefix has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_migration_by_prefix(self, app_label, name_prefix):
              """
              Return the migration(s) which match the given app label and name_prefix.
              """
              # Do the search
      Severity: Minor
      Found in django/db/migrations/loader.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 None
      Severity: Major
      Found in django/db/migrations/loader.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                            return self.graph.leaf_nodes(key[0])[0]
        Severity: Major
        Found in django/db/migrations/loader.py - About 30 mins to fix

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

              def collect_sql(self, plan):
                  """
                  Take a migration plan and return a list of collected SQL statements
                  that represent the best-efforts version of that plan.
                  """
          Severity: Minor
          Found in django/db/migrations/loader.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