fedspendingtransparency/usaspending-api

View on GitHub

Showing 118 of 226 total issues

File lookups.py has 270 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
This file defines a series of constants that represent the values used in
the API's "helper" tables.

Rather than define the values in the db setup scripts and then make db calls to
Severity: Minor
Found in usaspending_api/download/lookups.py - About 2 hrs to fix

    Function django_db_setup has a Cognitive Complexity of 28 (exceeds 15 allowed). Consider refactoring.
    Open

    def django_db_setup(
        request,
        django_test_environment: None,
        django_db_blocker,
        django_db_use_migrations: bool,
    Severity: Minor
    Found in usaspending_api/conftest.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

    File search.py has 261 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import itertools
    import logging
    
    from django.db.models import Q
    
    
    Severity: Minor
    Found in usaspending_api/awards/v2/filters/search.py - About 2 hrs to fix

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

          def generate_elasticsearch_query(cls, filter_values: List[str], query_type: _QueryType, **options) -> ES_Q:
              recipient_search_query = []
              words_to_escape = ["AND", "OR"]  # These need to be escaped to be included as text to be searched for
      
              for filter_value in filter_values:
      Severity: Minor
      Found in usaspending_api/common/query_with_filters.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

      File generate_cares_act_test_helpers.py has 258 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """
      Jira Ticket Number(s): DEV-5343
      
          Helper functions/classes for CARES Act test data generation.
      
      

        File load_multiple_submissions.py has 256 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import logging
        
        from datetime import timedelta
        from django.core.management import call_command
        from django.core.management.base import BaseCommand
        Severity: Minor
        Found in usaspending_api/etl/management/commands/load_multiple_submissions.py - About 2 hrs to fix

          Function generate_download has a Cognitive Complexity of 24 (exceeds 15 allowed). Consider refactoring.
          Open

          def generate_download(download_job: DownloadJob, origination: Optional[str] = None):
              """Create data archive files from the download job object"""
          
              # Parse data from download_job
              json_request = json.loads(download_job.json_request)
          Severity: Minor
          Found in usaspending_api/download/filestreaming/download_generation.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 get_business_categories_fpds has 60 lines of code (exceeds 45 allowed). Consider refactoring.
          Open

          def get_business_categories_fpds(row):
              # This function is supposed to be invoked as a Spark UDF with a named_struct containing the necessary
              # fields passed to it.
          
              def row_get(row, col_name):
          Severity: Major
          Found in usaspending_api/broker/helpers/get_business_categories.py - About 1 hr to fix

            Function agency_office_autocomplete has a Cognitive Complexity of 23 (exceeds 15 allowed). Consider refactoring.
            Open

                def agency_office_autocomplete(self, request):
                    """Returns a collection of agencies, sub-agencies, and offices that match the request."""
            
                    search_text, limit = self.get_request_payload(request)
                    # It's important to order by toptier fields so that results are deterministic between objects.
            Severity: Minor
            Found in usaspending_api/references/v2/views/autocomplete.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 build_elasticsearch_result has a Cognitive Complexity of 23 (exceeds 15 allowed). Consider refactoring.
            Open

                def build_elasticsearch_result(self, response: dict) -> Dict[str, dict]:
                    def _key_to_geo_code(key):
                        return f"{code_to_state[key[:2]]['fips']}{key[2:]}" if (key and key[:2] in code_to_state) else None
            
                    # Get the codes
            Severity: Minor
            Found in usaspending_api/search/v2/views/spending_by_geography.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 _handle_custom_award_download has a Cognitive Complexity of 22 (exceeds 15 allowed). Consider refactoring.
            Open

                def _handle_custom_award_download(self):
                    """
                    Custom Award Download allows different filters than other Award Download Endpoints
                    and thus it needs to be normalized before moving forward
                    # TODO: Refactor to use similar filters as Advanced Search download
            Severity: Minor
            Found in usaspending_api/download/v2/request_validations.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 build_elasticsearch_result has a Cognitive Complexity of 22 (exceeds 15 allowed). Consider refactoring.
            Open

                def build_elasticsearch_result(self, response: dict) -> List[dict]:
                    # Get the codes
                    agency_info_buckets = response.get("group_by_agg_key", {}).get("buckets", [])
                    code_list = [bucket.get("key") for bucket in agency_info_buckets if bucket.get("key")]
            
            

            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 download has 12 arguments (exceeds 6 allowed). Consider refactoring.
            Open

                def download(

              Function update_awarding_funding_agency has a Cognitive Complexity of 21 (exceeds 15 allowed). Consider refactoring.
              Open

                  def update_awarding_funding_agency(fiscal_year=None, file_type=None, page=1, limit=500000):
              
                      """
                      Uses the TransactionFPDS or TransactionFABS is present to update missing awarding and funding agency
                      in TransactionNormalized and Awards

              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 test_load_ids_dummy_id has 11 arguments (exceeds 6 allowed). Consider refactoring.
              Open

              def test_load_ids_dummy_id(
              Severity: Major
              Found in usaspending_api/etl/transaction_loaders/tests/test_fpds_loader.py - About 1 hr to fix

                Function process_cache_response has a Cognitive Complexity of 20 (exceeds 15 allowed). Consider refactoring.
                Open

                    def process_cache_response(self, view_instance, view_method, request, args, kwargs):
                        if is_experimental_elasticsearch_api(request):
                            # bypass cache altogether
                            response = view_method(view_instance, request, *args, **kwargs)
                            response = view_instance.finalize_response(request, response, *args, **kwargs)
                Severity: Minor
                Found in usaspending_api/common/cache_decorator.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 raw_search has a Cognitive Complexity of 20 (exceeds 15 allowed). Consider refactoring.
                Open

                    def raw_search(self, tiered_keys, child_layers, filter_string):
                        if not self._path_is_valid(tiered_keys):
                            return []
                        top = len(tiered_keys)
                        bottom = (child_layers if child_layers != -1 else 3) + top
                Severity: Minor
                Found in usaspending_api/references/v2/views/filter_tree/psc_filter_tree.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 total_obligation_queryset has a Cognitive Complexity of 20 (exceeds 15 allowed). Consider refactoring.
                Open

                def total_obligation_queryset(amount_obj, model, filters, is_subaward=False):
                    if can_use_total_obligation_enum(amount_obj):
                        bins = []
                        for v in amount_obj:
                            lower_bound = v.get("lower_bound")
                Severity: Minor
                Found in usaspending_api/awards/v2/filters/filter_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 10 arguments (exceeds 6 allowed). Consider refactoring.
                Open

                    def __init__(
                Severity: Major
                Found in usaspending_api/common/threaded_data_loader.py - About 1 hr to fix

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

                      def receive_messages(
                  Severity: Major
                  Found in usaspending_api/common/sqs/sqs_handler.py - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language