fedspendingtransparency/usaspending-api

View on GitHub

Showing 164 of 226 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        if fiscal_year:
            if arguments:
                query += " AND"
            else:
                query += " WHERE"
usaspending_api/broker/management/commands/update_transactions.py on lines 50..57

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 48.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

            submission_queryset = (
                submission_queryset.filter(toptier_code=toptier_agency.toptier_code, reporting_fiscal_year=fiscal_year)
                .order_by("-reporting_fiscal_year", "-reporting_fiscal_quarter")
                .annotate(fiscal_year=F("reporting_fiscal_year"), fiscal_quarter=F("reporting_fiscal_quarter"))
    Severity: Major
    Found in usaspending_api/accounts/views/financial_spending.py and 2 other locations - About 1 hr to fix
    usaspending_api/accounts/views/financial_balances.py on lines 38..41
    usaspending_api/accounts/views/financial_spending.py on lines 42..45

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

            submission_queryset = (
                submission_queryset.filter(toptier_code=toptier_agency.toptier_code, reporting_fiscal_year=fiscal_year)
                .order_by("-reporting_fiscal_year", "-reporting_fiscal_quarter")
                .annotate(fiscal_year=F("reporting_fiscal_year"), fiscal_quarter=F("reporting_fiscal_quarter"))
    Severity: Major
    Found in usaspending_api/accounts/views/financial_spending.py and 2 other locations - About 1 hr to fix
    usaspending_api/accounts/views/financial_balances.py on lines 38..41
    usaspending_api/accounts/views/financial_spending.py on lines 109..112

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

            submission_queryset = (
                submission_queryset.filter(toptier_code=toptier_agency.toptier_code, reporting_fiscal_year=fiscal_year)
                .order_by("-reporting_fiscal_year", "-reporting_fiscal_quarter")
                .annotate(fiscal_year=F("reporting_fiscal_year"), fiscal_quarter=F("reporting_fiscal_quarter"))
    Severity: Major
    Found in usaspending_api/accounts/views/financial_balances.py and 2 other locations - About 1 hr to fix
    usaspending_api/accounts/views/financial_spending.py on lines 42..45
    usaspending_api/accounts/views/financial_spending.py on lines 109..112

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

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

        def download(

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if fiscal_year:
                  fiscal_year = fiscal_year[0]
                  logger.info("Processing data for Fiscal Year " + str(fiscal_year))
              else:
                  fiscal_year = 2017
      Severity: Major
      Found in usaspending_api/etl/management/commands/load_fpds_csv.py and 1 other location - About 1 hr to fix
      usaspending_api/broker/management/commands/update_transactions.py on lines 384..388

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 40.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if business_category_set & {
                  "8a_program_participant",
                  "ability_one_program",
                  "dot_certified_disadvantaged_business_enterprise",
                  "emerging_small_business",
      Severity: Major
      Found in usaspending_api/broker/helpers/get_business_categories.py and 1 other location - About 1 hr to fix
      usaspending_api/broker/helpers/get_business_categories.py on lines 714..736

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 40.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if fiscal_year:
                  fiscal_year = fiscal_year[0]
                  logger.info("Processing data for Fiscal Year " + str(fiscal_year))
              else:
                  fiscal_year = 2017
      usaspending_api/etl/management/commands/load_fpds_csv.py on lines 37..41

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 40.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          if business_category_set & {
              "8a_program_participant",
              "ability_one_program",
              "dot_certified_disadvantaged_business_enterprise",
              "emerging_small_business",
      Severity: Major
      Found in usaspending_api/broker/helpers/get_business_categories.py and 1 other location - About 1 hr to fix
      usaspending_api/broker/helpers/get_business_categories.py on lines 282..304

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 40.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      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 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 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 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

        Severity
        Category
        Status
        Source
        Language