django/django

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

Summary

Maintainability
F
4 days
Test Coverage

Function _parse_column_or_constraint_definition has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring.
Open

    def _parse_column_or_constraint_definition(self, tokens, columns):
        token = None
        is_constraint_definition = None
        field_name = None
        constraint_name = None
Severity: Minor
Found in django/db/backends/sqlite3/introspection.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 introspection.py has 322 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import re
from collections import namedtuple

import sqlparse

Severity: Minor
Found in django/db/backends/sqlite3/introspection.py - About 3 hrs to fix

    Function get_constraints has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_constraints(self, cursor, table_name):
            """
            Retrieve any constraints or keys (unique, pk, fk, check, index) across
            one or more columns.
            """
    Severity: Minor
    Found in django/db/backends/sqlite3/introspection.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 _parse_table_constraints has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def _parse_table_constraints(self, sql, columns):
            # Check constraint parsing is based of SQLite syntax diagram.
            # https://www.sqlite.org/syntaxdiagrams.html#table-constraint
            statement = sqlparse.parse(sql)[0]
            constraints = {}
    Severity: Minor
    Found in django/db/backends/sqlite3/introspection.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_relations has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_relations(self, cursor, table_name):
            """
            Return a dictionary of {field_name: (field_name_other_table, other_table)}
            representing all relationships to the given table.
            """
    Severity: Minor
    Found in django/db/backends/sqlite3/introspection.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_primary_key_column has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_primary_key_column(self, cursor, table_name):
            """Return the column name of the primary key for the given table."""
            # Don't use PRAGMA because that causes issues with some transactions
            cursor.execute(
                "SELECT sql, type FROM sqlite_master "
    Severity: Minor
    Found in django/db/backends/sqlite3/introspection.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

    Avoid deeply nested control flow statements.
    Open

                            if unique_columns:
                                # Stop constraint parsing.
                                unique = False
                            continue
    Severity: Major
    Found in django/db/backends/sqlite3/introspection.py - About 45 mins to fix

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

                      if constraint_name is None:
                          if token.ttype in (sqlparse.tokens.Name, sqlparse.tokens.Keyword):
                              constraint_name = token.value
                          elif token.ttype == sqlparse.tokens.Literal.String.Symbol:
                              constraint_name = token.value[1:-1]
      Severity: Major
      Found in django/db/backends/sqlite3/introspection.py and 1 other location - About 4 hrs to fix
      django/db/backends/sqlite3/introspection.py on lines 269..273

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

      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_name is None:
                          if token.ttype in (sqlparse.tokens.Name, sqlparse.tokens.Keyword):
                              field_name = token.value
                          elif token.ttype == sqlparse.tokens.Literal.String.Symbol:
                              field_name = token.value[1:-1]
      Severity: Major
      Found in django/db/backends/sqlite3/introspection.py and 1 other location - About 4 hrs to fix
      django/db/backends/sqlite3/introspection.py on lines 248..252

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

      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 check:
                      if constraint_name:
                          constraints[constraint_name] = check
                      else:
                          unnamed_constrains_index += 1
      Severity: Major
      Found in django/db/backends/sqlite3/introspection.py and 1 other location - About 1 hr to fix
      django/db/backends/sqlite3/introspection.py on lines 324..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 44.

      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 unique:
                      if constraint_name:
                          constraints[constraint_name] = unique
                      else:
                          unnamed_constrains_index += 1
      Severity: Major
      Found in django/db/backends/sqlite3/introspection.py and 1 other location - About 1 hr to fix
      django/db/backends/sqlite3/introspection.py on lines 330..335

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

      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