django/django

View on GitHub
django/core/management/commands/inspectdb.py

Summary

Maintainability
F
4 days
Test Coverage

Function handle_inspection has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring.
Open

    def handle_inspection(self, options):
        connection = connections[options["database"]]
        # 'table_name_filter' is a stealth option
        table_name_filter = options.get("table_name_filter")

Severity: Minor
Found in django/core/management/commands/inspectdb.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 inspectdb.py has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import keyword
import re

from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS, connections
Severity: Minor
Found in django/core/management/commands/inspectdb.py - About 4 hrs to fix

    Function normalize_col_name has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def normalize_col_name(self, col_name, used_column_names, is_relation):
            """
            Modify the column name to make it Python-compatible as a field name
            """
            field_params = {}
    Severity: Minor
    Found in django/core/management/commands/inspectdb.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 get_field_type has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_field_type(self, connection, table_name, row):
            """
            Given the database connection, the table name, and the cursor row
            description, this routine will return the given field type name, as
            well as any additional keyword parameters and notes for the field.
    Severity: Minor
    Found in django/core/management/commands/inspectdb.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 get_meta has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_meta(
            self,
            table_name,
            constraints,
            column_to_field_name,
    Severity: Minor
    Found in django/core/management/commands/inspectdb.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 get_meta has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def get_meta(
    Severity: Minor
    Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if field_type == "AutoField(":
                                  continue
                              elif (
                                  field_type
                                  == connection.features.introspected_field_types["AutoField"]
      Severity: Major
      Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if not field_desc.endswith("("):
                                    field_desc += ", "
                                field_desc += ", ".join(
        Severity: Major
        Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if extra_params.pop("unique", False) or extra_params.get(
                                      "primary_key"
                                  ):
                                      rel_type = "OneToOneField"
                                  else:
          Severity: Major
          Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if len(primary_key_columns) > 1:
                                        comment_notes.append(
                                            "The composite primary key (%s) found, that is not "
                                            "supported. The first column is selected."
                                            % ", ".join(primary_key_columns)
            Severity: Major
            Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if rel_to in used_relations:
                                          extra_params["related_name"] = "%s_%s_set" % (
                                              model_name.lower(),
                                              att_name,
                                          )
              Severity: Major
              Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if rel_to in known_models:
                                            field_type = "%s(%s" % (rel_type, rel_to)
                                        else:
                                            field_type = "%s('%s'" % (rel_type, rel_to)
                                        if rel_to in used_relations:
                Severity: Major
                Found in django/core/management/commands/inspectdb.py - About 45 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status