django/django

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

Summary

Maintainability
D
2 days
Test Coverage

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

    def serialize(
        self,
        queryset,
        *,
        stream=None,
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 315 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 3 hrs to fix

    Function deserialize_m2m_values has a Cognitive Complexity of 13 (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):
    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(
    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)
      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)
        Severity: Major
        Found in django/core/serializers/base.py - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status