fedspendingtransparency/usaspending-api

View on GitHub

Showing 158 of 220 total issues

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

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

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

    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 39..43

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

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

            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

            Severity
            Category
            Status
            Source
            Language