django/django

View on GitHub
django/db/migrations/operations/models.py

Summary

Maintainability
F
4 days
Test Coverage

File models.py has 721 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.db import models
from django.db.migrations.operations.base import Operation
from django.db.migrations.state import ModelState
from django.db.models.options import normalize_together
from django.utils.functional import cached_property
Severity: Major
Found in django/db/migrations/operations/models.py - About 1 day to fix

    Function reduce has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

        def reduce(self, operation, app_label=None):
            if (isinstance(operation, DeleteModel) and
                    self.name_lower == operation.name_lower and
                    not self.options.get("proxy", False)):
                return []
    Severity: Minor
    Found in django/db/migrations/operations/models.py - About 7 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 state_forwards has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def state_forwards(self, app_label, state):
            # Add a new model.
            renamed_model = state.models[app_label, self.old_name_lower].clone()
            renamed_model.name = self.new_name
            state.models[app_label, self.new_name_lower] = renamed_model
    Severity: Minor
    Found in django/db/migrations/operations/models.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 database_forwards has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def database_forwards(self, app_label, schema_editor, from_state, to_state):
            new_model = to_state.apps.get_model(app_label, self.new_name)
            if self.allow_migrate_model(schema_editor.connection.alias, new_model):
                old_model = from_state.apps.get_model(app_label, self.old_name)
                # Move the main table
    Severity: Minor
    Found in django/db/migrations/operations/models.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

    Consider simplifying this complex logical expression.
    Open

            if (isinstance(operation, DeleteModel) and
                    self.name_lower == operation.name_lower and
                    not self.options.get("proxy", False)):
                return []
            elif isinstance(operation, RenameModel) and self.name_lower == operation.old_name_lower:
    Severity: Critical
    Found in django/db/migrations/operations/models.py - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                              if option:
                                  options[option_name] = option
                      order_with_respect_to = options.get('order_with_respect_to')
      Severity: Major
      Found in django/db/migrations/operations/models.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if through_model_tuple == old_model_tuple:
                                    if changed_field is None:
                                        changed_field = field.clone()
                                    changed_field.remote_field.through = new_remote_model
                        if changed_field:
        Severity: Major
        Found in django/db/migrations/operations/models.py - About 45 mins to fix

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

              def database_forwards(self, app_label, schema_editor, from_state, to_state):
                  to_model = to_state.apps.get_model(app_label, self.name)
                  if self.allow_migrate_model(schema_editor.connection.alias, to_model):
                      from_model = from_state.apps.get_model(app_label, self.name)
                      # Remove a field if we need to
          Severity: Minor
          Found in django/db/migrations/operations/models.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 references_model has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def references_model(self, name, app_label=None):
                  name_lower = name.lower()
                  if name_lower == self.name_lower:
                      return True
          
          
          Severity: Minor
          Found in django/db/migrations/operations/models.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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, name, fields, options=None, bases=None, managers=None):
          Severity: Minor
          Found in django/db/migrations/operations/models.py - About 35 mins to fix

            Avoid too many return statements within this function.
            Open

                    return super().reduce(operation, app_label=app_label)
            Severity: Major
            Found in django/db/migrations/operations/models.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return [
              Severity: Major
              Found in django/db/migrations/operations/models.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return [
                Severity: Major
                Found in django/db/migrations/operations/models.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return [
                  Severity: Major
                  Found in django/db/migrations/operations/models.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return [
                    Severity: Major
                    Found in django/db/migrations/operations/models.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return [
                      Severity: Major
                      Found in django/db/migrations/operations/models.py - About 30 mins to fix

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

                            def database_forwards(self, app_label, schema_editor, from_state, to_state):
                                new_model = to_state.apps.get_model(app_label, self.name)
                                if self.allow_migrate_model(schema_editor.connection.alias, new_model):
                                    old_model = from_state.apps.get_model(app_label, self.name)
                                    schema_editor.alter_db_table(
                        Severity: Minor
                        Found in django/db/migrations/operations/models.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