django/django

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

Summary

Maintainability
D
3 days
Test Coverage

Function from_model has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
Open

    def from_model(cls, model, exclude_rels=False):
        """Given a model, return a ModelState representing it."""
        # Deconstruct the fields
        fields = []
        for field in model._meta.local_fields:
Severity: Minor
Found in django/db/migrations/state.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

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

import copy
from contextlib import contextmanager

from django.apps import AppConfig
from django.apps.registry import Apps, apps as global_apps
Severity: Minor
Found in django/db/migrations/state.py - About 7 hrs to fix

    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 __init__ has a Cognitive Complexity of 13 (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
            self.fields = fields
            self.options = options or {}
    Severity: Minor
    Found in django/db/migrations/state.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 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

    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__(self, app_label, name, fields, options=None, bases=None, managers=None):
      Severity: Minor
      Found in django/db/migrations/state.py - About 45 mins to fix

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

            def __eq__(self, other):
                return (
                    (self.app_label == other.app_label) and
                    (self.name == other.name) and
                    (len(self.fields) == len(other.fields)) and
        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

        There are no issues that match your filters.

        Category
        Status