django/django

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

Summary

Maintainability
F
4 days
Test Coverage

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

    def migration_plan(self, targets, clean_start=False):
        """
        Given a set of targets, return a list of (Migration instance, backwards?).
        """
        plan = []
Severity: Minor
Found in django/db/migrations/executor.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 detect_soft_applied has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    def detect_soft_applied(self, project_state, migration):
        """
        Test whether a migration has been implicitly applied - that the
        tables or columns it would create exist. This is intended only for use
        on initial migrations (as it only looks for CreateModel and AddField).
Severity: Minor
Found in django/db/migrations/executor.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 _migrate_all_backwards has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def _migrate_all_backwards(self, plan, full_plan, fake):
        """
        Take a list of 2-tuples of the form (migration instance, True) and
        unapply them in reverse order they occur in the full_plan.

Severity: Minor
Found in django/db/migrations/executor.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

File executor.py has 295 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.apps.registry import apps as global_apps
from django.db import migrations, router

from .exceptions import InvalidMigrationPlan
from .loader import MigrationLoader
Severity: Minor
Found in django/db/migrations/executor.py - About 3 hrs to fix

    Function _migrate_all_forwards has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def _migrate_all_forwards(self, state, plan, full_plan, fake, fake_initial):
            """
            Take a list of 2-tuples of the form (migration instance, False) and
            apply them in the order they occur in the full_plan.
            """
    Severity: Minor
    Found in django/db/migrations/executor.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 apply_migration has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def apply_migration(self, state, migration, fake=False, fake_initial=False):
            """Run a migration forwards."""
            migration_recorded = False
            if self.progress_callback:
                self.progress_callback("apply_start", migration, fake)
    Severity: Minor
    Found in django/db/migrations/executor.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 migrate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def migrate(self, targets, plan=None, state=None, fake=False, fake_initial=False):
            """
            Migrate the database up to the given targets.
    
            Django first needs to create all project states before a migration is
    Severity: Minor
    Found in django/db/migrations/executor.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

    Avoid deeply nested control flow statements.
    Open

                            for migration in self.loader.graph.backwards_plan(root):
                                if migration in applied:
                                    plan.append((self.loader.graph.nodes[migration], True))
                                    applied.pop(migration)
                # If the migration is already applied, do backwards mode,
    Severity: Major
    Found in django/db/migrations/executor.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if migration in applied:
                                  plan.append((self.loader.graph.nodes[migration], True))
                                  applied.pop(migration)
                  else:
      Severity: Major
      Found in django/db/migrations/executor.py - About 45 mins to fix

        Function _migrate_all_forwards has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _migrate_all_forwards(self, state, plan, full_plan, fake, fake_initial):
        Severity: Minor
        Found in django/db/migrations/executor.py - About 35 mins to fix

          Function migrate has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def migrate(self, targets, plan=None, state=None, fake=False, fake_initial=False):
          Severity: Minor
          Found in django/db/migrations/executor.py - About 35 mins to fix

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

                def unapply_migration(self, state, migration, fake=False):
                    """Run a migration backwards."""
                    if self.progress_callback:
                        self.progress_callback("unapply_start", migration, fake)
                    if not fake:
            Severity: Minor
            Found in django/db/migrations/executor.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 (found_create_model_migration or found_add_field_migration), after_state
            Severity: Major
            Found in django/db/migrations/executor.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                  return False, project_state
              Severity: Major
              Found in django/db/migrations/executor.py - About 30 mins to fix

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

                    def _create_project_state(self, with_applied_migrations=False):
                        """
                        Create a project state including all the applications without
                        migrations and applied migrations if with_applied_migrations=True.
                        """
                Severity: Minor
                Found in django/db/migrations/executor.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 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/executor.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

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

                                    if root[0] == target[0]:
                                        for migration in self.loader.graph.backwards_plan(root):
                                            if migration in applied:
                                                plan.append((self.loader.graph.nodes[migration], True))
                                                applied.pop(migration)
                Severity: Major
                Found in django/db/migrations/executor.py and 1 other location - About 2 hrs to fix
                django/db/migrations/executor.py on lines 52..56

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

                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 node in next_in_app:
                                    for migration in self.loader.graph.backwards_plan(node):
                                        if migration in applied:
                                            plan.append((self.loader.graph.nodes[migration], True))
                                            applied.pop(migration)
                Severity: Major
                Found in django/db/migrations/executor.py and 1 other location - About 2 hrs to fix
                django/db/migrations/executor.py on lines 35..39

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

                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 migration.replaces:
                            for app_label, name in migration.replaces:
                                self.recorder.record_unapplied(app_label, name)
                        else:
                            self.recorder.record_unapplied(migration.app_label, migration.name)
                Severity: Major
                Found in django/db/migrations/executor.py and 1 other location - About 1 hr to fix
                django/db/migrations/executor.py on lines 255..261

                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

                    def record_migration(self, migration):
                        # For replacement migrations, record individual statuses
                        if migration.replaces:
                            for app_label, name in migration.replaces:
                                self.recorder.record_applied(app_label, name)
                Severity: Major
                Found in django/db/migrations/executor.py and 1 other location - About 1 hr to fix
                django/db/migrations/executor.py on lines 271..275

                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

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

                            applied_migrations = {
                                self.loader.graph.nodes[key] for key in self.loader.applied_migrations
                                if key in self.loader.graph.nodes
                Severity: Major
                Found in django/db/migrations/executor.py and 1 other location - About 1 hr to fix
                django/db/migrations/executor.py on lines 166..168

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

                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

                        applied_migrations = {
                            self.loader.graph.nodes[key] for key in self.loader.applied_migrations
                            if key in self.loader.graph.nodes
                Severity: Major
                Found in django/db/migrations/executor.py and 1 other location - About 1 hr to fix
                django/db/migrations/executor.py on lines 73..75

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

                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