django/django

View on GitHub
django/db/backends/oracle/operations.py

Summary

Maintainability
F
3 days
Test Coverage

File operations.py has 503 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import re
import uuid
from functools import lru_cache

Severity: Major
Found in django/db/backends/oracle/operations.py - About 1 day to fix

    DatabaseOperations has 54 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class DatabaseOperations(BaseDatabaseOperations):
        # Oracle uses NUMBER(5), NUMBER(11), and NUMBER(19) for integer fields.
        # SmallIntegerField uses NUMBER(11) instead of NUMBER(5), which is used by
        # SmallAutoField, to preserve backward compatibility.
        integer_field_ranges = {
    Severity: Major
    Found in django/db/backends/oracle/operations.py - About 7 hrs to fix

      Function get_db_converters has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_db_converters(self, expression):
              converters = super().get_db_converters(expression)
              internal_type = expression.output_field.get_internal_type()
              if internal_type == 'TextField':
                  converters.append(self.convert_textfield_value)
      Severity: Minor
      Found in django/db/backends/oracle/operations.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 sequence_reset_sql has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def sequence_reset_sql(self, style, model_list):
              from django.db import models
              output = []
              query = self._sequence_reset_sql
              for model in model_list:
      Severity: Minor
      Found in django/db/backends/oracle/operations.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 sql_flush has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def sql_flush(self, style, tables, sequences, allow_cascade=False):
              if tables:
                  truncated_tables = {table.upper() for table in tables}
                  constraints = set()
                  # Oracle's TRUNCATE CASCADE only works with ON DELETE CASCADE
      Severity: Minor
      Found in django/db/backends/oracle/operations.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 bulk_insert_sql has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def bulk_insert_sql(self, fields, placeholder_rows):
              query = []
              for row in placeholder_rows:
                  select = []
                  for i, placeholder in enumerate(row):
      Severity: Minor
      Found in django/db/backends/oracle/operations.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 datetime_trunc_sql has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def datetime_trunc_sql(self, lookup_type, field_name, tzname):
              field_name = self._convert_field_to_tz(field_name, tzname)
              # https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/ROUND-and-TRUNC-Date-Functions.html
              if lookup_type in ('year', 'month'):
                  sql = "TRUNC(%s, '%s')" % (field_name, lookup_type.upper())
      Severity: Minor
      Found in django/db/backends/oracle/operations.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 'FLOOR(%(lhs)s / POWER(2, %(rhs)s))' % {'lhs': lhs, 'rhs': rhs}
      Severity: Major
      Found in django/db/backends/oracle/operations.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return super().combine_expression(connector, sub_expressions)
        Severity: Major
        Found in django/db/backends/oracle/operations.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return "TO_CHAR(%s, 'IYYY')" % field_name
          Severity: Major
          Found in django/db/backends/oracle/operations.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name)
            Severity: Major
            Found in django/db/backends/oracle/operations.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return 'POWER(%s)' % ','.join(sub_expressions)
              Severity: Major
              Found in django/db/backends/oracle/operations.py - About 30 mins to fix

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

                    def date_extract_sql(self, lookup_type, field_name):
                        if lookup_type == 'week_day':
                            # TO_CHAR(field, 'D') returns an integer from 1-7, where 1=Sunday.
                            return "TO_CHAR(%s, 'D')" % field_name
                        elif lookup_type == 'iso_week_day':
                Severity: Minor
                Found in django/db/backends/oracle/operations.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 adapt_datetimefield_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def adapt_datetimefield_value(self, value):
                        """
                        Transform a datetime value to an object compatible with what is expected
                        by the backend driver for datetime columns.
                
                
                Severity: Minor
                Found in django/db/backends/oracle/operations.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 fetch_returned_insert_columns has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def fetch_returned_insert_columns(self, cursor, returning_params):
                        for param in returning_params:
                            value = param.get_value()
                            if value is None or value == []:
                                # cx_Oracle < 6.3 returns None, >= 6.3 returns empty list.
                Severity: Minor
                Found in django/db/backends/oracle/operations.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 last_executed_query has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def last_executed_query(self, cursor, sql, params):
                        # https://cx-oracle.readthedocs.io/en/latest/cursor.html#Cursor.statement
                        # The DB API definition does not define this attribute.
                        statement = cursor.statement
                        # Unlike Psycopg's `query` and MySQLdb`'s `_executed`, cx_Oracle's
                Severity: Minor
                Found in django/db/backends/oracle/operations.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 combine_expression has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def combine_expression(self, connector, sub_expressions):
                        lhs, rhs = sub_expressions
                        if connector == '%%':
                            return 'MOD(%s)' % ','.join(sub_expressions)
                        elif connector == '&':
                Severity: Minor
                Found in django/db/backends/oracle/operations.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