django/django

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

Summary

Maintainability
F
1 wk
Test Coverage

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

import logging
import operator
from datetime import datetime

from django.conf import settings
Severity: Major
Found in django/db/backends/base/schema.py - About 4 days to fix

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

        def _alter_field(
            self,
            model,
            old_field,
            new_field,
    Severity: Minor
    Found in django/db/backends/base/schema.py - About 2 days 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 77 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

      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 "
      Severity: Critical
      Found in django/db/backends/base/schema.py - About 4 hrs to fix

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

            def _constraint_names(
                self,
                model,
                column_names=None,
                unique=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

        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 afterward, like geometry fields with some backends).
                for field_names 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 _iter_column_sql has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            def _iter_column_sql(
                self, column_db_type, params, model, field, field_db_params, include_default
            ):
                yield column_db_type
                if collation := field_db_params.get("collation"):
        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 add_field has a Cognitive Complexity of 18 (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 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 17 (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 field.generated:
        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 alter_field has a Cognitive Complexity of 16 (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 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 create_model has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def create_model(self, model):
                """
                Create a table and any accompanying indexes or unique constraints for
                the given `model`.
                """
        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 13 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _create_index_sql(
        Severity: Major
        Found in django/db/backends/base/schema.py - About 1 hr to fix

          Function _alter_column_type_sql has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def _alter_column_type_sql(
                  self, model, old_field, new_field, new_type, old_collation, new_collation
              ):
                  """
                  Hook to specialize column type alteration for different backends,
          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 _constraint_names has 9 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _constraint_names(
          Severity: Major
          Found in django/db/backends/base/schema.py - About 1 hr to fix

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

                def _unique_sql(
            Severity: Major
            Found in django/db/backends/base/schema.py - About 1 hr to fix

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

                  def _create_unique_sql(
              Severity: Major
              Found in django/db/backends/base/schema.py - About 1 hr to fix

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

                    def _field_should_be_altered(self, old_field, new_field, ignore=None):
                        if not old_field.concrete and not new_field.concrete:
                            return False
                        ignore = ignore or set()
                        _, old_path, old_args, old_kwargs = old_field.deconstruct()
                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(
                Severity: Major
                Found in django/db/backends/base/schema.py - About 1 hr to fix

                  Function _delete_unique_sql has 8 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def _delete_unique_sql(
                  Severity: Major
                  Found in django/db/backends/base/schema.py - About 1 hr to fix

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

                        def _unique_supported(
                            self,
                            condition=None,
                            deferrable=None,
                            include=None,
                    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 9 (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 (
                    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 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 _iter_column_sql has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def _iter_column_sql(
                    Severity: Minor
                    Found in django/db/backends/base/schema.py - About 45 mins to fix

                      Function _alter_column_type_sql has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def _alter_column_type_sql(
                      Severity: Minor
                      Found in django/db/backends/base/schema.py - About 45 mins to fix

                        Consider simplifying this complex logical expression.
                        Open

                                if (
                                    self.connection.features.supports_foreign_keys
                                    and new_field.remote_field
                                    and (
                                        fks_dropped or not old_field.remote_field or not old_field.db_constraint
                        Severity: Major
                        Found in django/db/backends/base/schema.py - About 40 mins to fix

                          Function _unique_supported has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def _unique_supported(
                          Severity: Minor
                          Found in django/db/backends/base/schema.py - About 35 mins to fix

                            Function _alter_column_default_sql has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def _alter_column_default_sql(self, model, old_field, new_field, drop=False):
                                    """
                                    Hook to specialize column default alteration.
                            
                                    Return a (sql, params) fragment to add or drop (depending on the drop
                            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 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 _get_index_tablespace_sql has a Cognitive Complexity of 7 (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 settings.DEFAULT_INDEX_TABLESPACE:
                            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 _create_unique_sql has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def _create_unique_sql(
                                    self,
                                    model,
                                    fields,
                                    name=None,
                            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 _model_indexes_sql has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def _model_indexes_sql(self, model):
                                    """
                                    Return a list of all index SQL statements (field indexes, Meta.indexes)
                                    for the specified model.
                                    """
                            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 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

                            There are no issues that match your filters.

                            Category
                            Status