fedspendingtransparency/usaspending-api

View on GitHub

Showing 118 of 226 total issues

Function log_job_message has 10 arguments (exceeds 6 allowed). Consider refactoring.
Open

def log_job_message(
Severity: Major
Found in usaspending_api/common/sqs/sqs_job_logging.py - About 1 hr to fix

    Function build_query_filters has a Cognitive Complexity of 19 (exceeds 15 allowed). Consider refactoring.
    Open

    def build_query_filters(account_type, filters, account_level):
        if account_level not in ("treasury_account", "federal_account"):
            raise InvalidParameterException(
                'Invalid Parameter: account_level must be either "federal_account" or "treasury_account"'
            )
    Severity: Minor
    Found in usaspending_api/accounts/v2/filters/account_download.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 update_transaction_assistance has a Cognitive Complexity of 19 (exceeds 15 allowed). Consider refactoring.
    Open

        def update_transaction_assistance(db_cursor, fiscal_year=None, page=1, limit=500000):
    
            query = "SELECT * FROM published_fabs"
            arguments = []
    
    
    Severity: Minor
    Found in usaspending_api/broker/management/commands/update_transactions.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 parse_source has 9 arguments (exceeds 6 allowed). Consider refactoring.
    Open

    def parse_source(
    Severity: Major
    Found in usaspending_api/download/filestreaming/download_generation.py - About 50 mins to fix

      Function receive_messages has 9 arguments (exceeds 6 allowed). Consider refactoring.
      Open

          def receive_messages(
      Severity: Major
      Found in usaspending_api/common/sqs/sqs_handler.py - About 50 mins to fix

        Function _download_and_copy has 9 arguments (exceeds 6 allowed). Consider refactoring.
        Open

        def _download_and_copy(
        Severity: Major
        Found in usaspending_api/common/csv_stream_s3_to_pg.py - About 50 mins to fix

          Function update_transaction_contract has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
          Open

              def update_transaction_contract(db_cursor, fiscal_year=None, page=1, limit=500000):
          
                  # logger.info("Getting IDs for what's currently in the DB...")
                  # current_ids = TransactionFPDS.objects
                  #
          Severity: Minor
          Found in usaspending_api/broker/management/commands/update_transactions.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 broker_fpds_data:
                                  updated_row_count = run_spending_update_query(
                                      SPENDING_FPDS_UPDATE_SQL, "FPDS", broker_fpds_data
                                  )
                                  fpds_row_count += updated_row_count

            Function generate_elasticsearch_query has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
            Open

                def generate_elasticsearch_query(cls, filter_values: List[str], query_type: _QueryType, **options) -> ES_Q:
                    nested_path = options.get("nested_path", "")
                    def_codes_query = []
                    def_code_field = f"{nested_path}{'.' if nested_path else ''}disaster_emergency_fund_code{'s' if query_type != _QueryType.ACCOUNTS else ''}"
            
            
            Severity: Minor
            Found in usaspending_api/common/query_with_filters.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

            Function get_deleted_fpds_data_from_s3 has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
            Open

            def get_deleted_fpds_data_from_s3(date):
                ids_to_delete = []
                regex_str = ".*_delete_records_(IDV|award).*"
            
                if not date:
            Severity: Minor
            Found in usaspending_api/etl/transaction_loaders/data_load_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

            Function django_db_setup has 8 arguments (exceeds 6 allowed). Consider refactoring.
            Open

            def django_db_setup(
            Severity: Major
            Found in usaspending_api/conftest.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if "toptier_name" in v:
                                          funding_subtier |= Q(funding_subtier_agency_name=name) & Q(
                                              funding_toptier_agency_name=v["toptier_name"]
                                          )
                                      else:
              Severity: Major
              Found in usaspending_api/awards/v2/filters/search.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if "toptier_name" in v:
                                            awarding_subtier |= Q(awarding_subtier_agency_name=name) & Q(
                                                awarding_toptier_agency_name=v["toptier_name"]
                                            )
                                        else:
                Severity: Major
                Found in usaspending_api/awards/v2/filters/search.py - About 45 mins to fix

                  Function download_s3_object has 7 arguments (exceeds 6 allowed). Consider refactoring.
                  Open

                  def download_s3_object(
                  Severity: Major
                  Found in usaspending_api/common/helpers/s3_helpers.py - About 35 mins to fix

                    Function __init__ has 7 arguments (exceeds 6 allowed). Consider refactoring.
                    Open

                        def __init__(
                    Severity: Major
                    Found in usaspending_api/common/sqs/sqs_work_dispatcher.py - About 35 mins to fix

                      Function get_unreported_data_obj has 7 arguments (exceeds 6 allowed). Consider refactoring.
                      Open

                      def get_unreported_data_obj(
                      Severity: Major
                      Found in usaspending_api/spending_explorer/v2/filters/type_filter.py - About 35 mins to fix

                        Function delete_docs_by_unique_key has 7 arguments (exceeds 6 allowed). Consider refactoring.
                        Open

                        def delete_docs_by_unique_key(
                        Severity: Major
                        Found in usaspending_api/etl/elasticsearch_loader_helpers/delete_data.py - About 35 mins to fix

                          Function delete_transactions has 7 arguments (exceeds 6 allowed). Consider refactoring.
                          Open

                          def delete_transactions(
                          Severity: Major
                          Found in usaspending_api/etl/elasticsearch_loader_helpers/delete_data.py - About 35 mins to fix

                            Function load_data_into_model has 7 arguments (exceeds 6 allowed). Consider refactoring.
                            Open

                                def load_data_into_model(self, model_instance, fields, field_map, value_map, row, logger, as_dict=False):
                            Severity: Major
                            Found in usaspending_api/common/threaded_data_loader.py - About 35 mins to fix

                              Function write_csv_file has 7 arguments (exceeds 6 allowed). Consider refactoring.
                              Open

                              def write_csv_file(
                              Severity: Major
                              Found in usaspending_api/common/etl/spark.py - About 35 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language