airbnb/caravel

View on GitHub
superset/models/helpers.py

Summary

Maintainability
F
2 wks
Test Coverage

File helpers.py has 1800 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Severity: Major
Found in superset/models/helpers.py - About 4 days to fix

    Function get_sqla_query has a Cognitive Complexity of 228 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_sqla_query(  # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
            self,
            apply_fetch_values_predicate: bool = False,
            columns: Optional[list[Column]] = None,
            extras: Optional[dict[str, Any]] = None,
    Severity: Minor
    Found in superset/models/helpers.py - About 4 days 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 import_from_dict has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

        def import_from_dict(
            # pylint: disable=too-many-arguments,too-many-branches,too-many-locals
            cls,
            dict_rep: dict[Any, Any],
            parent: Optional[Any] = None,
    Severity: Minor
    Found in superset/models/helpers.py - About 6 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

    ExploreMixin has 47 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ExploreMixin:  # pylint: disable=too-many-public-methods
        """
        Allows any flask_appbuilder.Model (Query, Table, etc.)
        to be used to power a chart inside /explore
        """
    Severity: Minor
    Found in superset/models/helpers.py - About 6 hrs to fix

      Function filter_values_handler has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def filter_values_handler(  # pylint: disable=too-many-arguments
              values: Optional[FilterValues],
              operator: str,
              target_generic_type: utils.GenericDataType,
              target_native_type: Optional[str] = None,
      Severity: Minor
      Found in superset/models/helpers.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

      Function get_sqla_query has 24 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get_sqla_query(  # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
      Severity: Major
      Found in superset/models/helpers.py - About 3 hrs to fix

        Function get_sqla_query has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def get_sqla_query(  # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
                self,
                apply_fetch_values_predicate: bool = False,
                columns: Optional[list[Column]] = None,
                extras: Optional[dict[str, Any]] = None,
        Severity: Major
        Found in superset/models/helpers.py - About 2 hrs to fix

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

              def _normalize_prequery_result_type(
                  self,
                  row: pd.Series,
                  dimension: str,
                  columns_by_name: dict[str, "TableColumn"],
          Severity: Minor
          Found in superset/models/helpers.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 export_to_dict has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              def export_to_dict(
                  self,
                  recursive: bool = True,
                  include_parent_ref: bool = False,
                  include_defaults: bool = False,
          Severity: Minor
          Found in superset/models/helpers.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 __init__ has 12 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(  # pylint: disable=too-many-arguments
          Severity: Major
          Found in superset/models/helpers.py - About 1 hr to fix

            Function dttm_sql_literal has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def dttm_sql_literal(self, dttm: datetime, col: "TableColumn") -> str:
                    """Convert datetime object to a SQL expression string"""
            
                    sql = (
                        self.db_engine_spec.convert_dttm(col.type, dttm, db_extra=self.db_extra)
            Severity: Minor
            Found in superset/models/helpers.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 filter_values_handler has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def filter_values_handler(  # pylint: disable=too-many-arguments
            Severity: Major
            Found in superset/models/helpers.py - About 1 hr to fix

              Function export_schema has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def export_schema(
                      cls, recursive: bool = True, include_parent_ref: bool = False
                  ) -> dict[str, Any]:
                      """Export schema as a dictionary"""
                      parent_excludes = set()
              Severity: Minor
              Found in superset/models/helpers.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 exc_query has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def exc_query(self, qry: Any) -> QueryResult:
                      qry_start_dttm = datetime.now()
                      query_str_ext = self.get_query_str_extended(qry)
                      sql = query_str_ext.sql
                      status = QueryStatus.SUCCESS
              Severity: Minor
              Found in superset/models/helpers.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 get_time_filter has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def get_time_filter(  # pylint: disable=too-many-arguments
              Severity: Major
              Found in superset/models/helpers.py - About 50 mins to fix

                Function import_from_dict has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def import_from_dict(
                Severity: Minor
                Found in superset/models/helpers.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if eq:
                                              cond = or_(is_null_cond, sqla_col.in_(eq_without_none))
                                          else:
                                              cond = is_null_cond
                                      else:
                  Severity: Major
                  Found in superset/models/helpers.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if target_generic_type != GenericDataType.STRING:
                                                sqla_col = sa.cast(sqla_col, sa.String)
                    
                    
                    Severity: Major
                    Found in superset/models/helpers.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if op == utils.FilterOperator.LIKE.value:
                                                  where_clause_and.append(sqla_col.like(eq))
                                              else:
                                                  where_clause_and.append(sqla_col.ilike(eq))
                                          elif (
                      Severity: Major
                      Found in superset/models/helpers.py - About 45 mins to fix

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

                            def get_sqla_row_level_filters(
                                self,
                                template_processor: BaseTemplateProcessor,
                            ) -> list[TextClause]:
                                """
                        Severity: Minor
                        Found in superset/models/helpers.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 too many return statements within this function.
                        Open

                                        return utils.cast_to_boolean(value)
                        Severity: Major
                        Found in superset/models/helpers.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return value
                          Severity: Major
                          Found in superset/models/helpers.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return f"""'{dttm.strftime("%Y-%m-%d %H:%M:%S.%f")}'"""
                            Severity: Major
                            Found in superset/models/helpers.py - About 30 mins to fix

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

                              def validate_adhoc_subquery(
                                  sql: str,
                                  database_id: int,
                                  default_schema: str,
                              ) -> str:
                              Severity: Minor
                              Found in superset/models/helpers.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 make_orderby_compatible has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  def make_orderby_compatible(
                                      self, select_exprs: list[ColumnElement], orderby_exprs: list[ColumnElement]
                                  ) -> None:
                                      """
                                      If needed, make sure aliases for selected columns are not used in
                              Severity: Minor
                              Found in superset/models/helpers.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