django/django

View on GitHub
django/db/backends/base/schema.py

Summary

Maintainability
F
1 wk
Test Coverage

File schema.py has 941 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
from datetime import datetime

from django.db.backends.ddl_references import (
    Columns, ForeignKeyName, IndexName, Statement, Table,
Severity: Major
Found in django/db/backends/base/schema.py - About 2 days to fix

    Function _alter_field has a Cognitive Complexity of 86 (exceeds 5 allowed). Consider refactoring.
    Open

        def _alter_field(self, model, old_field, new_field, old_type, new_type,
                         old_db_params, new_db_params, strict=False):
            """Perform a "physical" (non-ManyToMany) field update."""
            # Drop any FK constraints, we'll remake them later
            fks_dropped = set()
    Severity: Minor
    Found in django/db/backends/base/schema.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

    BaseDatabaseSchemaEditor has 57 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BaseDatabaseSchemaEditor:
        """
        This class and its subclasses are responsible for emitting schema-changing
        statements to the databases - model creation/removal/alteration, field
        renaming, index fiddling, and so on.
    Severity: Major
    Found in django/db/backends/base/schema.py - About 1 day to fix

      Function _constraint_names has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          def _constraint_names(self, model, column_names=None, unique=None,
                                primary_key=None, index=None, foreign_key=None,
                                check=None, type_=None, exclude=None):
              """Return all constraint names matching the columns and conditions."""
              if column_names is not None:
      Severity: Minor
      Found in django/db/backends/base/schema.py - About 4 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

      Consider simplifying this complex logical expression.
      Open

              if ((old_type is None and old_field.remote_field is None) or
                      (new_type is None and new_field.remote_field is None)):
                  raise ValueError(
                      "Cannot alter field %s into %s - they do not properly define "
                      "db_type (are you using a badly-written custom field?)" %
      Severity: Critical
      Found in django/db/backends/base/schema.py - About 3 hrs to fix

        Function table_sql has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            def table_sql(self, model):
                """Take a model and return its table definition."""
                # Add any unique_togethers (always deferred, as some fields might be
                # created afterwards, like geometry fields with some backends).
                for fields in model._meta.unique_together:
        Severity: Minor
        Found in django/db/backends/base/schema.py - About 3 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 column_sql has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def column_sql(self, model, field, include_default=False):
                """
                Take a field and return its column definition.
                The field must already have had set_attributes_from_name() called.
                """
        Severity: Minor
        Found in django/db/backends/base/schema.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 _effective_default has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def _effective_default(field):
                # This method allows testing its logic without a connection.
                if field.has_default():
                    default = field.get_default()
                elif not field.null and field.blank and field.empty_strings_allowed:
        Severity: Minor
        Found in django/db/backends/base/schema.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 _create_index_sql has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _create_index_sql(self, model, fields, *, name=None, suffix='', using='',
        Severity: Major
        Found in django/db/backends/base/schema.py - About 1 hr to fix

          Function _constraint_names has 9 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _constraint_names(self, model, column_names=None, unique=None,
          Severity: Major
          Found in django/db/backends/base/schema.py - About 1 hr to fix

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

                def alter_field(self, model, old_field, new_field, strict=False):
                    """
                    Allow a field's type, uniqueness, nullability, default, column,
                    constraints, etc. to be modified.
                    `old_field` is required to compute the necessary changes.
            Severity: Minor
            Found in django/db/backends/base/schema.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 _alter_field has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def _alter_field(self, model, old_field, new_field, old_type, new_type,
            Severity: Major
            Found in django/db/backends/base/schema.py - About 1 hr to fix

              Function remove_field has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def remove_field(self, model, field):
                      """
                      Remove a field from a model. Usually involves deleting a column,
                      but for M2Ms may involve deleting a table.
                      """
              Severity: Minor
              Found in django/db/backends/base/schema.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 add_field has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def add_field(self, model, field):
                      """
                      Create a field on a model. Usually involves adding a column, but may
                      involve adding a table instead (for M2M fields).
                      """
              Severity: Minor
              Found in django/db/backends/base/schema.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 execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def execute(self, sql, params=()):
                      """Execute the given SQL statement, with optional parameters."""
                      # Don't perform the transactional DDL check if SQL is being collected
                      # as it's not going to be executed anyway.
                      if not self.collect_sql and self.connection.in_atomic_block and not self.connection.features.can_rollback_ddl:
              Severity: Minor
              Found in django/db/backends/base/schema.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 delete_model has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def delete_model(self, model):
                      """Delete a model from the database."""
                      # Handle auto-created intermediary models
                      for field in model._meta.local_many_to_many:
                          if field.remote_field.through._meta.auto_created:
              Severity: Minor
              Found in django/db/backends/base/schema.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 alter_db_table has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def alter_db_table(self, model, old_db_table, new_db_table):
                      """Rename the table a model points to."""
                      if (old_db_table == new_db_table or
                          (self.connection.features.ignores_table_name_case and
                              old_db_table.lower() == new_db_table.lower())):
              Severity: Minor
              Found in django/db/backends/base/schema.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 _get_index_tablespace_sql has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _get_index_tablespace_sql(self, model, fields, db_tablespace=None):
                      if db_tablespace is None:
                          if len(fields) == 1 and fields[0].db_tablespace:
                              db_tablespace = fields[0].db_tablespace
                          elif model._meta.db_tablespace:
              Severity: Minor
              Found in django/db/backends/base/schema.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 _create_unique_sql has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _create_unique_sql(self, model, columns, name=None, condition=None):
                      def create_unique_name(*args, **kwargs):
                          return self.quote_name(self._create_index_name(*args, **kwargs))
              
                      table = Table(model._meta.db_table, self.quote_name)
              Severity: Minor
              Found in django/db/backends/base/schema.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