django/django

View on GitHub
django/contrib/admin/checks.py

Summary

Maintainability
F
5 days
Test Coverage

File checks.py has 979 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from itertools import chain

from django.apps import apps
from django.conf import settings
from django.contrib.admin.utils import (
Severity: Major
Found in django/contrib/admin/checks.py - About 2 days to fix

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

    class BaseModelAdminChecks:
    
        def check(self, admin_obj, **kwargs):
            return [
                *self._check_autocomplete_fields(admin_obj),
    Severity: Minor
    Found in django/contrib/admin/checks.py - About 3 hrs to fix

      Function check_dependencies has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      def check_dependencies(**kwargs):
          """
          Check that the admin's dependencies are correctly installed.
          """
          if not apps.is_installed('django.contrib.admin'):
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_ordering_item has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_ordering_item(self, obj, field_name, label):
              """ Check that `ordering` refers to existing fields. """
              if isinstance(field_name, (Combinable, OrderBy)):
                  if not isinstance(field_name, OrderBy):
                      field_name = field_name.asc()
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_list_filter_item has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_list_filter_item(self, obj, item, label):
              """
              Check one item of `list_filter`, i.e. check if it is one of three options:
              1. 'field' -- a basic field filter, possibly w/ relationships (e.g.
                 'field__rel')
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_field_spec_item has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_field_spec_item(self, obj, field_name, label):
              if field_name in obj.readonly_fields:
                  # Stuff can be put in fields that isn't actually a model field if
                  # it's in readonly_fields, readonly_fields will handle the
                  # validation of such things.
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_list_display_item has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_list_display_item(self, obj, item, label):
              if callable(item):
                  return []
              elif hasattr(obj, item):
                  return []
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_list_editable_item has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_list_editable_item(self, obj, field_name, label):
              try:
                  field = obj.model._meta.get_field(field_name)
              except FieldDoesNotExist:
                  return refer_to_missing_field(field=field_name, option=label, obj=obj, id='admin.E121')
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_date_hierarchy has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_date_hierarchy(self, obj):
              """ Check that date_hierarchy refers to DateField or DateTimeField. """
      
              if obj.date_hierarchy is None:
                  return []
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_action_permission_methods has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_action_permission_methods(self, obj):
              """
              Actions with an allowed_permission attribute require the ModelAdmin to
              implement a has_<perm>_permission() method for each permission.
              """
      Severity: Minor
      Found in django/contrib/admin/checks.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 _check_readonly_fields_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def _check_readonly_fields_item(self, obj, field_name, label):
              if callable(field_name):
                  return []
              elif hasattr(obj, field_name):
                  return []
      Severity: Minor
      Found in django/contrib/admin/checks.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

      Avoid too many return statements within this function.
      Open

                      return []
      Severity: Major
      Found in django/contrib/admin/checks.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return []
        Severity: Major
        Found in django/contrib/admin/checks.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return refer_to_missing_field(field=field_name, option=label, obj=obj, id='admin.E033')
          Severity: Major
          Found in django/contrib/admin/checks.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return [
            Severity: Major
            Found in django/contrib/admin/checks.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return list(chain.from_iterable(
              Severity: Major
              Found in django/contrib/admin/checks.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return inline(obj.model, obj.admin_site).check()
                Severity: Major
                Found in django/contrib/admin/checks.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return []
                  Severity: Major
                  Found in django/contrib/admin/checks.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return []
                    Severity: Major
                    Found in django/contrib/admin/checks.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return []
                      Severity: Major
                      Found in django/contrib/admin/checks.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                        return []
                        Severity: Major
                        Found in django/contrib/admin/checks.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return [
                          Severity: Major
                          Found in django/contrib/admin/checks.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                            return []
                            Severity: Major
                            Found in django/contrib/admin/checks.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return [
                              Severity: Major
                              Found in django/contrib/admin/checks.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                return []
                                Severity: Major
                                Found in django/contrib/admin/checks.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                          return list(chain.from_iterable(
                                  Severity: Major
                                  Found in django/contrib/admin/checks.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                    return []
                                    Severity: Major
                                    Found in django/contrib/admin/checks.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                      return [
                                      Severity: Major
                                      Found in django/contrib/admin/checks.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    return must_be('a list or tuple', option="%s[1]['fields']" % label, obj=obj, id='admin.E008')
                                        Severity: Major
                                        Found in django/contrib/admin/checks.py - About 30 mins to fix

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

                                              def _check_autocomplete_fields_item(self, obj, field_name, label):
                                                  """
                                                  Check that an item in `autocomplete_fields` is a ForeignKey or a
                                                  ManyToManyField and that the item has a related ModelAdmin with
                                                  search_fields defined.
                                          Severity: Minor
                                          Found in django/contrib/admin/checks.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 _check_fieldsets_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                              def _check_fieldsets_item(self, obj, fieldset, label, seen_fields):
                                                  """ Check an item of `fieldsets`, i.e. check that this is a pair of a
                                                  set name and a dictionary containing "fields" key. """
                                          
                                                  if not isinstance(fieldset, (list, tuple)):
                                          Severity: Minor
                                          Found in django/contrib/admin/checks.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