django/django

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

Summary

Maintainability
F
3 days
Test Coverage

Function _alter_field has a Cognitive Complexity of 34 (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."""
        # Use "ALTER TABLE ... RENAME COLUMN" if only the column name
        # changed and there aren't any constraints.
Severity: Minor
Found in django/db/backends/sqlite3/schema.py - About 5 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 _remake_table has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    def _remake_table(self, model, create_field=None, delete_field=None, alter_field=None):
        """
        Shortcut to transform a model from old_model into new_model

        This follows the correct procedure to perform non-rename or column
Severity: Minor
Found in django/db/backends/sqlite3/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

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

import copy
from decimal import Decimal

from django.apps.registry import Apps
from django.db import NotSupportedError
Severity: Minor
Found in django/db/backends/sqlite3/schema.py - About 3 hrs to fix

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

        def _is_referenced_by_fk_constraint(self, table_name, column_name=None, ignore_self=False):
            """
            Return whether or not the provided table name is referenced by another
            one. If `column_name` is specified, only references pointing to that
            column are considered. If `ignore_self` is True, self-referential
    Severity: Minor
    Found in django/db/backends/sqlite3/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 _remake_table has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def _remake_table(self, model, create_field=None, delete_field=None, alter_field=None):
            """
            Shortcut to transform a model from old_model into new_model
    
            This follows the correct procedure to perform non-rename or column
    Severity: Minor
    Found in django/db/backends/sqlite3/schema.py - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if (self.connection.features.can_alter_table_rename_column and
                  old_field.column != new_field.column and
                  self.column_sql(model, old_field) == self.column_sql(model, new_field) and
                  not (old_field.remote_field and old_field.db_constraint or
                       new_field.remote_field and new_field.db_constraint)):
      Severity: Major
      Found in django/db/backends/sqlite3/schema.py - About 1 hr to fix

        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/sqlite3/schema.py - About 1 hr to fix

          Function quote_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def quote_value(self, value):
                  # The backend "mostly works" without this function and there are use
                  # cases for compiling Python without the sqlite3 libraries (e.g.
                  # security hardening).
                  try:
          Severity: Minor
          Found in django/db/backends/sqlite3/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, handle_autom2m=True):
                  if handle_autom2m:
                      super().delete_model(model)
                  else:
                      # Delete the table (and only that)
          Severity: Minor
          Found in django/db/backends/sqlite3/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

          Avoid too many return statements within this function.
          Open

                      return "X'%s'" % value.hex()
          Severity: Major
          Found in django/db/backends/sqlite3/schema.py - About 30 mins to fix

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

                def alter_field(self, model, old_field, new_field, strict=False):
                    if not self._field_should_be_altered(old_field, new_field):
                        return
                    old_field_name = old_field.name
                    table_name = model._meta.db_table
            Severity: Minor
            Found in django/db/backends/sqlite3/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 remove_field has a Cognitive Complexity of 6 (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/sqlite3/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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def add_constraint(self, model, constraint):
                    if isinstance(constraint, UniqueConstraint) and constraint.condition:
                        super().add_constraint(model, constraint)
                    else:
                        self._remake_table(model)
            Severity: Major
            Found in django/db/backends/sqlite3/schema.py and 1 other location - About 1 hr to fix
            django/db/backends/sqlite3/schema.py on lines 427..431

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 46.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def remove_constraint(self, model, constraint):
                    if isinstance(constraint, UniqueConstraint) and constraint.condition:
                        super().remove_constraint(model, constraint)
                    else:
                        self._remake_table(model)
            Severity: Major
            Found in django/db/backends/sqlite3/schema.py and 1 other location - About 1 hr to fix
            django/db/backends/sqlite3/schema.py on lines 421..425

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 46.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    unique_together = [
                        [rename_mapping.get(n, n) for n in unique]
                        for unique in model._meta.unique_together
            Severity: Minor
            Found in django/db/backends/sqlite3/schema.py and 1 other location - About 30 mins to fix
            django/db/backends/sqlite3/schema.py on lines 227..229

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if field.many_to_many and field.remote_field.through._meta.auto_created:
                        return self.create_model(field.remote_field.through)
            Severity: Minor
            Found in django/db/backends/sqlite3/schema.py and 1 other location - About 30 mins to fix
            django/db/backends/sqlite3/schema.py on lines 213..214

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        if delete_field.many_to_many and delete_field.remote_field.through._meta.auto_created:
                            return self.delete_model(delete_field.remote_field.through)
            Severity: Minor
            Found in django/db/backends/sqlite3/schema.py and 1 other location - About 30 mins to fix
            django/db/backends/sqlite3/schema.py on lines 328..329

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    index_together = [
                        [rename_mapping.get(n, n) for n in index]
                        for index in model._meta.index_together
            Severity: Minor
            Found in django/db/backends/sqlite3/schema.py and 1 other location - About 30 mins to fix
            django/db/backends/sqlite3/schema.py on lines 220..222

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status