django/django

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

Summary

Maintainability
F
3 days
Test Coverage

Function _remake_table has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

    def _remake_table(
        self, model, create_field=None, delete_field=None, alter_fields=None
    ):
        """
        Shortcut to transform a model from old_model into new_model
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 _alter_field has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

    def _alter_field(
        self,
        model,
        old_field,
        new_field,
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

File schema.py has 376 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 5 hrs to fix

    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_fields=None
        ):
            """
            Shortcut to transform a model from old_model into new_model
    Severity: Minor
    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(
      Severity: Major
      Found in django/db/backends/sqlite3/schema.py - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                if field.many_to_many and field.remote_field.through._meta.auto_created:
                    self.create_model(field.remote_field.through)
                elif (
                    # Primary keys and unique fields are not supported in ALTER TABLE
                    # ADD COLUMN.
        Severity: Major
        Found in django/db/backends/sqlite3/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/sqlite3/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 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

          Consider simplifying this complex logical expression.
          Open

                  if (
                      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
          Severity: Major
          Found in django/db/backends/sqlite3/schema.py - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                    if field.many_to_many:
                        # For implicit M2M tables, delete the auto-created table
                        if field.remote_field.through._meta.auto_created:
                            self.delete_model(field.remote_field.through)
                        # For explicit "through" M2M fields, do nothing
            Severity: Major
            Found in django/db/backends/sqlite3/schema.py - About 40 mins to fix

              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

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

                    def add_constraint(self, model, constraint):
                        if isinstance(constraint, UniqueConstraint) and (
                            constraint.condition
                            or constraint.contains_expressions
                            or constraint.include
                Severity: Major
                Found in django/db/backends/sqlite3/schema.py and 1 other location - About 2 hrs to fix
                django/db/backends/sqlite3/schema.py on lines 479..488

                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 59.

                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
                            or constraint.contains_expressions
                            or constraint.include
                Severity: Major
                Found in django/db/backends/sqlite3/schema.py and 1 other location - About 2 hrs to fix
                django/db/backends/sqlite3/schema.py on lines 468..477

                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 59.

                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

                                        old_field.remote_field.through._meta.get_field(
                                            old_field.m2m_reverse_field_name()
                                        ),
                                        new_field.remote_field.through._meta.get_field(
                                            new_field.m2m_reverse_field_name()
                Severity: Minor
                Found in django/db/backends/sqlite3/schema.py and 1 other location - About 45 mins to fix
                django/db/backends/sqlite3/schema.py on lines 430..434

                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 35.

                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

                                        old_field.remote_field.through._meta.get_field(
                                            old_field.m2m_field_name()
                                        ),
                                        new_field.remote_field.through._meta.get_field(
                                            new_field.m2m_field_name()
                Severity: Minor
                Found in django/db/backends/sqlite3/schema.py and 1 other location - About 45 mins to fix
                django/db/backends/sqlite3/schema.py on lines 419..423

                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 35.

                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