treyhunner/django-simple-history

View on GitHub

Showing 18 of 47 total issues

File models.py has 833 lines of code (exceeds 500 allowed). Consider refactoring.
Open

import copy
import importlib
import uuid
import warnings
from functools import partial
Severity: Major
Found in simple_history/models.py - About 1 day to fix

    HistoricalRecords has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class HistoricalRecords:
        DEFAULT_MODEL_NAME_PREFIX = "Historical"
    
        thread = context = LocalContext()  # retain thread for backwards compatibility
        m2m_models = {}
    Severity: Minor
    Found in simple_history/models.py - About 3 hrs to fix

      Function __init__ has 27 arguments (exceeds 7 allowed). Consider refactoring.
      Open

          def __init__(
      Severity: Major
      Found in simple_history/models.py - About 3 hrs to fix

        Function copy_fields has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
        Open

            def copy_fields(self, model):
                """
                Creates copies of the model's original fields, returning
                a dictionary mapping field name to copied field object.
                """
        Severity: Minor
        Found in simple_history/models.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 _process has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
        Open

            def _process(self, to_process, date_back=None, dry_run=True):
                if date_back:
                    stop_date = timezone.now() - timezone.timedelta(minutes=date_back)
                else:
                    stop_date = None
        Severity: Minor
        Found in simple_history/management/commands/clean_duplicate_history.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 diff_against has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
        Open

            def diff_against(self, old_history, excluded_fields=None, included_fields=None):
                if not isinstance(old_history, type(self)):
                    raise TypeError(
                        ("unsupported type(s) for diffing: " "'{}' and '{}'").format(
                            type(self), type(old_history)
        Severity: Minor
        Found in simple_history/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

        Function history_view has a Cognitive Complexity of 13 (exceeds 7 allowed). Consider refactoring.
        Open

            def history_view(self, request, object_id, extra_context=None):
                """The 'history' admin view for this model."""
                request.current_app = self.admin_site.name
                model = self.model
                opts = model._meta
        Severity: Minor
        Found in simple_history/admin.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 __init__ has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def __init__(
                self,
                verbose_name=None,
                verbose_name_plural=None,
                bases=(models.Model,),
        Severity: Minor
        Found in simple_history/models.py - About 1 hr to fix

          Function bulk_create_with_history has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def bulk_create_with_history(
              objs,
              model,
              batch_size=None,
              ignore_conflicts=False,
          Severity: Minor
          Found in simple_history/utils.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 update_change_reason has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
          Open

          def update_change_reason(instance, reason):
              attrs = {}
              model = type(instance)
              manager = instance if instance.pk is not None else model
              history = get_history_manager_for_model(manager)
          Severity: Minor
          Found in simple_history/utils.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 bulk_update_with_history has 9 arguments (exceeds 7 allowed). Consider refactoring.
          Open

          def bulk_update_with_history(
          Severity: Major
          Found in simple_history/utils.py - About 45 mins to fix

            Function bulk_create_with_history has 8 arguments (exceeds 7 allowed). Consider refactoring.
            Open

            def bulk_create_with_history(
            Severity: Major
            Found in simple_history/utils.py - About 35 mins to fix

              Function transform_field has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
              Open

              def transform_field(field):
                  """Customize field appropriately for use in historical model"""
                  field.name = field.attname
                  if isinstance(field, models.BigAutoField):
                      field.__class__ = models.BigIntegerField
              Severity: Minor
              Found in simple_history/models.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 finalize has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
              Open

                  def finalize(self, sender, **kwargs):
                      inherited = False
                      if self.cls is not sender:  # set in concrete
                          inherited = self.inherit and issubclass(sender, self.cls)
                          if not inherited:
              Severity: Minor
              Found in simple_history/models.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 history_form_view has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
              Open

                  def history_form_view(self, request, object_id, version_id, extra_context=None):
                      request.current_app = self.admin_site.name
                      original_opts = self.model._meta
                      model = getattr(
                          self.model, self.model._meta.simple_history_manager_attribute
              Severity: Minor
              Found in simple_history/admin.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 latest_of_each has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
              Open

                  def latest_of_each(self):
                      """
                      Ensures results in the queryset are the latest historical record for each
                      primary key.  Deletions are not removed.
              
              
              Severity: Minor
              Found in simple_history/manager.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 _bulk_history_create has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
              Open

                  def _bulk_history_create(self, model, batch_size):
                      """Save a copy of all instances to the historical model.
              
                      :param model: Model you want to bulk create
                      :param batch_size: number of models to create at once.
              Severity: Minor
              Found in simple_history/management/commands/populate_history.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 handle has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
              Open

                  def handle(self, *args, **options):
                      self.verbosity = options["verbosity"]
              
                      to_process = set()
                      model_strings = options.get("models", []) or args
              Severity: Minor
              Found in simple_history/management/commands/populate_history.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

              Severity
              Category
              Status
              Source
              Language