django/django

View on GitHub
django/core/serializers/base.py

Summary

Maintainability
D
1 day
Test Coverage

Function serialize has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    def serialize(self, queryset, *, stream=None, fields=None, use_natural_foreign_keys=False,
                  use_natural_primary_keys=False, progress_output=None, object_count=0, **options):
        """
        Serialize a queryset.
        """
Severity: Minor
Found in django/core/serializers/base.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

File base.py has 257 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Module for abstract serializer/unserializer base classes.
"""
from io import StringIO

Severity: Minor
Found in django/core/serializers/base.py - About 2 hrs to fix

    Function deserialize_m2m_values has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def deserialize_m2m_values(field, field_value, using, handle_forward_references):
        model = field.remote_field.model
        if hasattr(model._default_manager, 'get_by_natural_key'):
            def m2m_convert(value):
                if hasattr(value, '__iter__') and not isinstance(value, str):
    Severity: Minor
    Found in django/core/serializers/base.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 deserialize_fk_value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def deserialize_fk_value(field, field_value, using, handle_forward_references):
        if field_value is None:
            return None
        model = field.remote_field.model
        default_manager = model._default_manager
    Severity: Minor
    Found in django/core/serializers/base.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 serialize has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def serialize(self, queryset, *, stream=None, fields=None, use_natural_foreign_keys=False,
    Severity: Major
    Found in django/core/serializers/base.py - About 1 hr to fix

      Function save_deferred_fields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def save_deferred_fields(self, using=None):
              self.m2m_data = {}
              for field, field_value in self.deferred_fields.items():
                  opts = self.object._meta
                  label = opts.app_label + '.' + opts.model_name
      Severity: Minor
      Found in django/core/serializers/base.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

      Avoid deeply nested control flow statements.
      Open

                              if self.selected_fields is None or field.attname[:-3] in self.selected_fields:
                                  self.handle_fk_field(obj, field)
                  for field in concrete_model._meta.local_many_to_many:
      Severity: Major
      Found in django/core/serializers/base.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if self.selected_fields is None or field.attname in self.selected_fields:
                                    self.handle_field(obj, field)
                            else:
        Severity: Major
        Found in django/core/serializers/base.py - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status