django/django

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

Summary

Maintainability
F
4 days
Test Coverage

File state.py has 791 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
from collections import defaultdict
from contextlib import contextmanager
from functools import partial

Severity: Major
Found in django/db/migrations/state.py - About 1 day to fix

    ProjectState has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ProjectState:
        """
        Represent the entire project's overall state. This is the item that is
        passed around - do it here rather than at the app level so that cross-app
        FKs/etc. resolve properly.
    Severity: Minor
    Found in django/db/migrations/state.py - About 4 hrs to fix

      Function rename_field has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          def rename_field(self, app_label, model_name, old_name, new_name):
              model_key = app_label, model_name
              model_state = self.models[model_key]
              # Rename the field.
              fields = model_state.fields
      Severity: Minor
      Found in django/db/migrations/state.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 _find_reload_model has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def _find_reload_model(self, app_label, model_name, delay=False):
              if delay:
                  self.is_delayed = True
      
              related_models = set()
      Severity: Minor
      Found in django/db/migrations/state.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 rename_model has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

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

          def alter_field(self, app_label, model_name, name, field, preserve_default):
              if not preserve_default:
                  field = field.clone()
                  field.default = NOT_PROVIDED
              else:
      Severity: Minor
      Found in django/db/migrations/state.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

      Function render_multiple has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def render_multiple(self, model_states):
              # We keep trying to render the models in a loop, ignoring invalid
              # base errors, until the size of the unrendered models doesn't
              # decrease by at least one, meaning there's a base dependency loop/
              # missing base.
      Severity: Minor
      Found in django/db/migrations/state.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

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

          def __init__(
              self, app_label, name, fields, options=None, bases=None, managers=None
          ):
              self.app_label = app_label
              self.name = name
      Severity: Minor
      Found in django/db/migrations/state.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

      Avoid deeply nested control flow statements.
      Open

                              if not index.name:
                                  index.set_name_with_model(model)
                          options["indexes"] = indexes
      Severity: Major
      Found in django/db/migrations/state.py - About 45 mins to fix

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

            def _reload(self, related_models):
                # Unregister all related models
                with self.apps.bulk_update():
                    for rel_app_label, rel_model_name in related_models:
                        self.apps.unregister_model(rel_app_label, rel_model_name)
        Severity: Minor
        Found in django/db/migrations/state.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 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Minor
        Found in django/db/migrations/state.py - About 45 mins to fix

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

              def update_model_field_relation(
          Severity: Minor
          Found in django/db/migrations/state.py - About 35 mins to fix

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

                def alter_field(self, app_label, model_name, name, field, preserve_default):
            Severity: Minor
            Found in django/db/migrations/state.py - About 35 mins to fix

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

                  def add_field(self, app_label, model_name, name, field, preserve_default):
              Severity: Minor
              Found in django/db/migrations/state.py - About 35 mins to fix

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

                    def remove_model(self, app_label, model_name):
                        model_key = app_label, model_name
                        del self.models[model_key]
                        if self._relations is not None:
                            self._relations.pop(model_key, None)
                Severity: Minor
                Found in django/db/migrations/state.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

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

                    def alter_model_options(self, app_label, model_name, options, option_keys=None):
                        model_state = self.models[app_label, model_name]
                        model_state.options = {**model_state.options, **options}
                        if option_keys:
                            for key in option_keys:
                Severity: Minor
                Found in django/db/migrations/state.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 _find_concrete_model_from_proxy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _find_concrete_model_from_proxy(self, proxy_models, model_state):
                        for base in model_state.bases:
                            if not (isinstance(base, str) or issubclass(base, models.Model)):
                                continue
                            base_key = make_model_tuple(base)
                Severity: Minor
                Found in django/db/migrations/state.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