django/django

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

Summary

Maintainability
D
2 days
Test Coverage

File base.py has 501 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
SQLite backend for the sqlite3 module in the standard library.
"""
import datetime
import decimal
Severity: Major
Found in django/db/backends/sqlite3/base.py - About 1 day to fix

    Function check_constraints has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def check_constraints(self, table_names=None):
            """
            Check each table name in `table_names` for rows with invalid foreign
            key references. This method is intended to be used in conjunction with
            `disable_constraint_checking()` and `enable_constraint_checking()`, to
    Severity: Minor
    Found in django/db/backends/sqlite3/base.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_new_connection has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def get_new_connection(self, conn_params):
            conn = Database.connect(**conn_params)
            if PY38:
                create_deterministic_function = functools.partial(
                    conn.create_function,
    Severity: Major
    Found in django/db/backends/sqlite3/base.py - About 2 hrs to fix

      Function _sqlite_datetime_parse has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def _sqlite_datetime_parse(dt, tzname=None, conn_tzname=None):
          if dt is None:
              return None
          try:
              dt = backend_utils.typecast_timestamp(dt)
      Severity: Minor
      Found in django/db/backends/sqlite3/base.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 _sqlite_datetime_trunc has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _sqlite_datetime_trunc(lookup_type, dt, tzname, conn_tzname):
          dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)
          if dt is None:
              return None
          if lookup_type == 'year':
      Severity: Minor
      Found in django/db/backends/sqlite3/base.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

      Avoid deeply nested control flow statements.
      Open

                              for bad_row in cursor.fetchall():
                                  raise IntegrityError(
                                      "The row in table '%s' with primary key '%s' has an "
                                      "invalid foreign key: %s.%s contains a value '%s' that "
                                      "does not have a corresponding value in %s.%s." % (
      Severity: Major
      Found in django/db/backends/sqlite3/base.py - About 45 mins to fix

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

        def _sqlite_datetime_extract(lookup_type, dt, tzname=None, conn_tzname=None):
            dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)
            if dt is None:
                return None
            if lookup_type == 'week_day':
        Severity: Minor
        Found in django/db/backends/sqlite3/base.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 "%i-%02i-%02i" % (dt.year, dt.month, dt.day)
        Severity: Major
        Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return math.ceil(dt.month / 3)
          Severity: Major
          Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return "%i-%02i-%02i 00:00:00" % (dt.year, dt.month, dt.day)
            Severity: Major
            Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return "%i-%02i-%02i %02i:%02i:%02i" % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
              Severity: Major
              Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return dt.isocalendar()[0]
                Severity: Major
                Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return getattr(dt, lookup_type)
                  Severity: Major
                  Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return "%i-%02i-%02i 00:00:00" % (dt.year, dt.month, dt.day)
                    Severity: Major
                    Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return "%i-%02i-%02i" % (dt.year, dt.month, dt.day)
                      Severity: Major
                      Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return "%02i:%02i:%02i" % (dt.hour, dt.minute, dt.second)
                        Severity: Major
                        Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return "%i-%02i-%02i %02i:00:00" % (dt.year, dt.month, dt.day, dt.hour)
                          Severity: Major
                          Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return "%i-%02i-%02i %02i:%02i:00" % (dt.year, dt.month, dt.day, dt.hour, dt.minute)
                            Severity: Major
                            Found in django/db/backends/sqlite3/base.py - About 30 mins to fix

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

                              def _sqlite_date_trunc(lookup_type, dt):
                                  dt = _sqlite_datetime_parse(dt)
                                  if dt is None:
                                      return None
                                  if lookup_type == 'year':
                              Severity: Minor
                              Found in django/db/backends/sqlite3/base.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