airbnb/caravel

View on GitHub
superset/connectors/sqla/models.py

Summary

Maintainability
F
1 wk
Test Coverage

File models.py has 1779 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/connectors/sqla/models.py - About 4 days to fix

    SqlaTable has 58 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SqlaTable(
        Model,
        BaseDatasource,
        ExploreMixin,
    ):  # pylint: disable=too-many-public-methods
    Severity: Major
    Found in superset/connectors/sqla/models.py - About 1 day to fix

      BaseDatasource has 43 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class BaseDatasource(AuditMixinNullable, ImportExportMixin):  # pylint: disable=too-many-public-methods
          """A common interface to objects that are queryable
          (tables and datasources)"""
      
          # ---------------------------------------------------------------
      Severity: Minor
      Found in superset/connectors/sqla/models.py - About 5 hrs to fix

        Function data_for_slices has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
        Open

            def data_for_slices(  # pylint: disable=too-many-locals
                self, slices: list[Slice]
            ) -> dict[str, Any]:
                """
                The representation of the datasource containing only the required data
        Severity: Minor
        Found in superset/connectors/sqla/models.py - About 4 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 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: FilterValues | None,
                operator: str,
                target_generic_type: GenericDataType,
                target_native_type: str | None = None,
        Severity: Minor
        Found in superset/connectors/sqla/models.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_fk_many_from_list has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_fk_many_from_list(
                object_list: list[Any],
                fkmany: list[Column],
                fkmany_class: builtins.type[TableColumn | SqlMetric],
                key_attr: str,
        Severity: Minor
        Found in superset/connectors/sqla/models.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 adhoc_column_to_sqla has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def adhoc_column_to_sqla(  # pylint: disable=too-many-locals
                self,
                col: AdhocColumn,
                force_type_check: bool = False,
                template_processor: BaseTemplateProcessor | None = None,
        Severity: Minor
        Found in superset/connectors/sqla/models.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 fetch_metadata has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def fetch_metadata(self) -> MetadataResult:
                """
                Fetches the metadata for the table and merges it in
        
                :return: Tuple with lists of added, removed and modified column names.
        Severity: Minor
        Found in superset/connectors/sqla/models.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 query has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def query(self, query_obj: QueryObjectDict) -> QueryResult:
                qry_start_dttm = datetime.now()
                query_str_ext = self.get_query_str_extended(query_obj)
                sql = query_str_ext.sql
                status = QueryStatus.SUCCESS
        Severity: Minor
        Found in superset/connectors/sqla/models.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 adhoc_metric_to_sqla has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def adhoc_metric_to_sqla(
                self,
                metric: AdhocMetric,
                columns_by_name: dict[str, TableColumn],
                template_processor: BaseTemplateProcessor | None = None,
        Severity: Minor
        Found in superset/connectors/sqla/models.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_sqla_row_level_filters has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_sqla_row_level_filters(
                self,
                template_processor: Optional[BaseTemplateProcessor] = None,
            ) -> list[TextClause]:
                """
        Severity: Minor
        Found in superset/connectors/sqla/models.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 filter_values_handler has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

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

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

              def has_extra_cache_key_calls(self, query_obj: QueryObjectDict) -> bool:
                  """
                  Detects the presence of calls to `ExtraCache` methods in items in query_obj that
                  can be templated. If any are present, the query must be evaluated to extract
                  additional keys for the cache key. This method is needed to avoid executing the
          Severity: Minor
          Found in superset/connectors/sqla/models.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 column_name := column_.get("column_name"):
                                      column_names.add(column_name)
          
                      # Columns used in query filters
                      column_names.update(
          Severity: Major
          Found in superset/connectors/sqla/models.py - About 45 mins to fix

            Function query_datasources_by_permissions has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def query_datasources_by_permissions(  # pylint: disable=invalid-name
            Severity: Minor
            Found in superset/connectors/sqla/models.py - About 35 mins to fix

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

                  def get_timestamp_expression(
                      self,
                      time_grain: str | None,
                      label: str | None = None,
                      template_processor: BaseTemplateProcessor | None = None,
              Severity: Minor
              Found in superset/connectors/sqla/models.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 value
              Severity: Major
              Found in superset/connectors/sqla/models.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

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

                  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/connectors/sqla/models.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 get_sqla_col has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_sqla_col(
                          self,
                          label: str | None = None,
                          template_processor: BaseTemplateProcessor | None = None,
                      ) -> Column:
                  Severity: Minor
                  Found in superset/connectors/sqla/models.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