Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4a8b217
[DEV-13899] Update Django and DjangoRestFramework versions
aguest-kc May 7, 2026
8b135fd
[DEV-13899] Remove deprecated index_together
aguest-kc May 7, 2026
06d934c
[DEV-13899] Update OpClass import
aguest-kc May 7, 2026
d5591b8
[DEV-13899] Rename old index_together index
aguest-kc May 7, 2026
021e7a0
[DEV-13899] Ruff fixes
aguest-kc May 7, 2026
7b15504
[DEV-13899] Revert uv.lock revision number
aguest-kc May 7, 2026
6a20723
[DEV-13899] Ignore migrations in ruff Github action
aguest-kc May 7, 2026
e438dfd
[DEV-13899] Update to support Django 5.2 SQL alias changes
aguest-kc May 7, 2026
6cf3e61
[DEV-13899] Ruff fixes
aguest-kc May 7, 2026
f18c966
[DEV-13899] Fixing downloads
aguest-kc May 11, 2026
d37518c
Merge branch 'qat' into ftr/dev-13899-django-5.2-upgrade
aguest-kc May 26, 2026
8fb7c69
[DEV-13899] Ruff fixes
aguest-kc May 26, 2026
30b5371
[DEV-13899] Revert download_generation.py changes
aguest-kc May 27, 2026
17f8ea9
[DEV-13899] Fix tests
aguest-kc Jun 1, 2026
1794e59
Merge branch 'qat' into ftr/dev-13899-django-5.2-upgrade
aguest-kc Jun 2, 2026
ba1aff3
[DEV-13899] Fixed nulls_last ordering error
DavidMikolaKC Jun 16, 2026
78e0826
[DEV-13899] Ruff Lint Fix
DavidMikolaKC Jun 17, 2026
3266cde
[DEV-13899] Resolved Duplicate Historical Lookup Keys
DavidMikolaKC Jun 22, 2026
e6394aa
Merge branch 'qat' of https://github.com/fedspendingtransparency/usas…
DavidMikolaKC Jun 22, 2026
f52126a
Added missing exceptions for python strings
DavidMikolaKC Jun 22, 2026
d6e56f7
[DEV-13899] Fixed Improper Group By Replacement Indexing
DavidMikolaKC Jun 23, 2026
8884c29
[Dev-13899] Ruff Lint Fixes
DavidMikolaKC Jun 23, 2026
3a05a8b
[Dev-13899] Value Error Fix
DavidMikolaKC Jun 23, 2026
7415445
Merge branch 'qat' into ftr/dev-13899-django-5.2-upgrade
aguest-kc Jun 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/code-style-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
with:
files: |
**.py
files_ignore: |
**/migrations/**
Comment on lines +40 to +41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

separator: " "

- name: Check If `changed-python-files` Is An Empty String
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ dependencies = [
"django-debug-toolbar==4.3.*",
"django-extensions==3.2.*",
"django-spaghetti-and-meatballs==0.4.*",
"Django==4.2.*",
"Django==5.2.*",
"django_cte==1.3.*",
"djangorestframework==3.15.*",
"djangorestframework==3.17.*",
"docutils>=0.10,<0.17",
"drf-api-tracking==1.8.4",
"drf-extensions==0.7.*",
Expand Down Expand Up @@ -233,3 +233,6 @@ pycodestyle.max-line-length = 120
"PLR0913", # too-many-arguments; avoid conflict with too many fixtures
"PLR0915", # too-many-statements; avoid conflict with long fixtures
]
"**/disaster/management/sql/spark/**.py" = [
"E501", # Line too long
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.2.14 on 2026-05-07 12:57

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('awards', '0114_alter_ctodlinkageupdates_award_id'),
]

operations = [
migrations.RenameIndex(
model_name='financialaccountsbyawards',
new_name='financial_a_disaste_396e45_idx',
old_fields=('disaster_emergency_fund', 'submission', 'award', 'piid', 'fain', 'uri', 'parent_award_id', 'transaction_obligated_amount', 'gross_outlay_amount_by_award_cpe'),
),
]
32 changes: 16 additions & 16 deletions usaspending_api/awards/models/financial_accounts_by_awards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django_cte import CTEManager
from django.db.models import Q
from django_cte import CTEManager

from usaspending_api.common.models import DataSourceTrackedModel

Expand Down Expand Up @@ -154,21 +154,6 @@ class FinancialAccountsByAwards(AbstractFinancialAccountsByAwards):
class Meta:
managed = True
db_table = "financial_accounts_by_awards"
index_together = [
# This index dramatically sped up disaster endpoint queries. VERY IMPORTANT! It needs
# to cover all of the fields being queried in order to eek out maximum performance.
[
"disaster_emergency_fund",
"submission",
"award",
"piid",
"fain",
"uri",
"parent_award_id",
"transaction_obligated_amount",
"gross_outlay_amount_by_award_cpe",
]
]
indexes = [
models.Index(
fields=["submission_id", "treasury_account_id"],
Expand All @@ -193,4 +178,19 @@ class Meta:
name="faba_subid_awardkey_sums_idx",
condition=Q(disaster_emergency_fund__in=["L", "M", "N", "O", "P", "U", "V"]),
),
# This index dramatically sped up disaster endpoint queries. VERY IMPORTANT! It needs
# to cover all of the fields being queried in order to eek out maximum performance.
models.Index(
fields=[
"disaster_emergency_fund",
"submission",
"award",
"piid",
"fain",
"uri",
"parent_award_id",
"transaction_obligated_amount",
"gross_outlay_amount_by_award_cpe",
]
),
]
4 changes: 3 additions & 1 deletion usaspending_api/awards/models/transaction_normalized.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def __str__(self):
class Meta:
managed = False
db_table = "vw_transaction_normalized"
index_together = ["award", "action_date"]
indexes = [
models.Index(fields=["award", "action_date"])
]


NORM_ALT_COL_NAMES_IN_TRANSACTION_SEARCH = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ SELECT
"transaction_fpds"."cost_accounting_standards" AS "cost_accounting_standards_clause_code",
"transaction_fpds"."cost_accounting_stand_desc" AS "cost_accounting_standards_clause",
"transaction_fpds"."government_furnished_prope" AS "government_furnished_property_code",
"transaction_fpds"."government_furnished_prope" AS "government_furnished_property",
"transaction_fpds"."government_furnished_desc" AS "government_furnished_property",
"transaction_fpds"."sea_transportation" AS "sea_transportation_code",
"transaction_fpds"."sea_transportation_desc" AS "sea_transportation",
"transaction_fpds"."consolidated_contract" AS "consolidated_contract_code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ SELECT
"financial_accounts_by_program_activity_object_class"."ussgl480100_undelivered_orders_obligations_unpaid_fyb" AS "USSGL480100_undelivered_orders_obligations_unpaid_FYB",
"financial_accounts_by_program_activity_object_class"."ussgl488100_upward_adjust_pri_undeliv_order_oblig_unpaid_cpe" AS "USSGL488100_upward_adj_prior_year_undeliv_orders_oblig_unpaid",
"financial_accounts_by_program_activity_object_class"."obligations_delivered_orders_unpaid_total_cpe" AS "obligations_delivered_orders_unpaid_total",
"financial_accounts_by_program_activity_object_class"."obligations_delivered_orders_unpaid_total_cpe" AS "obligations_delivered_orders_unpaid_total_FYB",
"financial_accounts_by_program_activity_object_class"."obligations_delivered_orders_unpaid_total_fyb" AS "obligations_delivered_orders_unpaid_total_FYB",
"financial_accounts_by_program_activity_object_class"."ussgl490100_delivered_orders_obligations_unpaid_cpe" AS "USSGL490100_delivered_orders_obligations_unpaid",
"financial_accounts_by_program_activity_object_class"."ussgl490100_delivered_orders_obligations_unpaid_fyb" AS "USSGL490100_delivered_orders_obligations_unpaid_FYB",
"financial_accounts_by_program_activity_object_class"."ussgl498100_upward_adjust_pri_deliv_orders_oblig_unpaid_cpe" AS "USSGL498100_upward_adj_of_prior_year_deliv_orders_oblig_unpaid",
"financial_accounts_by_program_activity_object_class"."gross_outlay_amount_by_program_object_class_cpe" AS "gross_outlay_amount_FYB_to_period_end",
"financial_accounts_by_program_activity_object_class"."gross_outlay_amount_by_program_object_class_fyb" AS "gross_outlay_amount_FYB",
"financial_accounts_by_program_activity_object_class"."gross_outlays_undelivered_orders_prepaid_total_cpe" AS "gross_outlays_undelivered_orders_prepaid_total",
"financial_accounts_by_program_activity_object_class"."gross_outlays_undelivered_orders_prepaid_total_cpe" AS "gross_outlays_undelivered_orders_prepaid_total_FYB",
"financial_accounts_by_program_activity_object_class"."gross_outlays_undelivered_orders_prepaid_total_fyb" AS "gross_outlays_undelivered_orders_prepaid_total_FYB",
"financial_accounts_by_program_activity_object_class"."ussgl480200_undelivered_orders_oblig_prepaid_advanced_cpe" AS "USSGL480200_undelivered_orders_obligations_prepaid_advanced",
"financial_accounts_by_program_activity_object_class"."ussgl480200_undelivered_orders_oblig_prepaid_advanced_fyb" AS "USSGL480200_undelivered_orders_obligations_prepaid_advanced_FYB",
"financial_accounts_by_program_activity_object_class"."ussgl488200_up_adjust_pri_undeliv_order_oblig_ppaid_adv_cpe" AS "USSGL488200_upward_adj_prior_year_undeliv_orders_oblig_prepaid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ SELECT
"latest_transaction"."cost_accounting_standards" AS "cost_accounting_standards_clause_code",
"latest_transaction"."cost_accounting_stand_desc" AS "cost_accounting_standards_clause",
"latest_transaction"."government_furnished_prope" AS "government_furnished_property_code",
"latest_transaction"."government_furnished_prope" AS "government_furnished_property",
"latest_transaction"."government_furnished_desc" AS "government_furnished_property",
"latest_transaction"."sea_transportation" AS "sea_transportation_code",
"latest_transaction"."sea_transportation_desc" AS "sea_transportation",
"latest_transaction"."consolidated_contract" AS "consolidated_contract_code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
financial_accounts_by_program_activity_object_class.ussgl480100_undelivered_orders_obligations_unpaid_fyb AS USSGL480100_undelivered_orders_obligations_unpaid_FYB,
financial_accounts_by_program_activity_object_class.ussgl488100_upward_adjust_pri_undeliv_order_oblig_unpaid_cpe AS USSGL488100_upward_adj_prior_year_undeliv_orders_oblig_unpaid,
financial_accounts_by_program_activity_object_class.obligations_delivered_orders_unpaid_total_cpe AS obligations_delivered_orders_unpaid_total,
financial_accounts_by_program_activity_object_class.obligations_delivered_orders_unpaid_total_cpe AS obligations_delivered_orders_unpaid_total_FYB,
financial_accounts_by_program_activity_object_class.obligations_delivered_orders_unpaid_total_fyb AS obligations_delivered_orders_unpaid_total_FYB,
financial_accounts_by_program_activity_object_class.ussgl490100_delivered_orders_obligations_unpaid_cpe AS USSGL490100_delivered_orders_obligations_unpaid,
financial_accounts_by_program_activity_object_class.ussgl490100_delivered_orders_obligations_unpaid_fyb AS USSGL490100_delivered_orders_obligations_unpaid_FYB,
financial_accounts_by_program_activity_object_class.ussgl498100_upward_adjust_pri_deliv_orders_oblig_unpaid_cpe AS USSGL498100_upward_adj_of_prior_year_deliv_orders_oblig_unpaid,
financial_accounts_by_program_activity_object_class.gross_outlay_amount_by_program_object_class_cpe AS gross_outlay_amount_FYB_to_period_end,
financial_accounts_by_program_activity_object_class.gross_outlay_amount_by_program_object_class_fyb AS gross_outlay_amount_FYB,
financial_accounts_by_program_activity_object_class.gross_outlays_undelivered_orders_prepaid_total_cpe AS gross_outlays_undelivered_orders_prepaid_total,
financial_accounts_by_program_activity_object_class.gross_outlays_undelivered_orders_prepaid_total_cpe AS gross_outlays_undelivered_orders_prepaid_total_FYB,
financial_accounts_by_program_activity_object_class.gross_outlays_undelivered_orders_prepaid_total_fyb AS gross_outlays_undelivered_orders_prepaid_total_FYB,
financial_accounts_by_program_activity_object_class.ussgl480200_undelivered_orders_oblig_prepaid_advanced_cpe AS USSGL480200_undelivered_orders_obligations_prepaid_advanced,
financial_accounts_by_program_activity_object_class.ussgl480200_undelivered_orders_oblig_prepaid_advanced_fyb AS USSGL480200_undelivered_orders_obligations_prepaid_advanced_FYB,
financial_accounts_by_program_activity_object_class.ussgl488200_up_adjust_pri_undeliv_order_oblig_ppaid_adv_cpe AS USSGL488200_upward_adj_prior_year_undeliv_orders_oblig_prepaid,
Expand Down Expand Up @@ -117,14 +117,14 @@
financial_accounts_by_program_activity_object_class.ussgl480100_undelivered_orders_obligations_unpaid_fyb,
financial_accounts_by_program_activity_object_class.ussgl488100_upward_adjust_pri_undeliv_order_oblig_unpaid_cpe,
financial_accounts_by_program_activity_object_class.obligations_delivered_orders_unpaid_total_cpe,
financial_accounts_by_program_activity_object_class.obligations_delivered_orders_unpaid_total_cpe,
financial_accounts_by_program_activity_object_class.obligations_delivered_orders_unpaid_total_fyb,
financial_accounts_by_program_activity_object_class.ussgl490100_delivered_orders_obligations_unpaid_cpe,
financial_accounts_by_program_activity_object_class.ussgl490100_delivered_orders_obligations_unpaid_fyb,
financial_accounts_by_program_activity_object_class.ussgl498100_upward_adjust_pri_deliv_orders_oblig_unpaid_cpe,
financial_accounts_by_program_activity_object_class.gross_outlay_amount_by_program_object_class_cpe,
financial_accounts_by_program_activity_object_class.gross_outlay_amount_by_program_object_class_fyb,
financial_accounts_by_program_activity_object_class.gross_outlays_undelivered_orders_prepaid_total_cpe,
financial_accounts_by_program_activity_object_class.gross_outlays_undelivered_orders_prepaid_total_cpe,
financial_accounts_by_program_activity_object_class.gross_outlays_undelivered_orders_prepaid_total_fyb,
financial_accounts_by_program_activity_object_class.ussgl480200_undelivered_orders_oblig_prepaid_advanced_cpe,
financial_accounts_by_program_activity_object_class.ussgl480200_undelivered_orders_oblig_prepaid_advanced_fyb,
financial_accounts_by_program_activity_object_class.ussgl488200_up_adjust_pri_undeliv_order_oblig_ppaid_adv_cpe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
latest_transaction.cost_accounting_standards AS cost_accounting_standards_clause_code,
latest_transaction.cost_accounting_stand_desc AS cost_accounting_standards_clause,
latest_transaction.government_furnished_prope AS government_furnished_property_code,
latest_transaction.government_furnished_prope AS government_furnished_property,
latest_transaction.government_furnished_desc AS government_furnished_property,
latest_transaction.sea_transportation AS sea_transportation_code,
latest_transaction.sea_transportation_desc AS sea_transportation,
latest_transaction.consolidated_contract AS consolidated_contract_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def award_financial_df(spark: SparkSession) -> DataFrame:
ts.recipient_name,
ts.recipient_name_raw,
ts.parent_uei.alias("recipient_parent_uei"),
ts.parent_uei.alias("recipient_parent_duns"),
ts.parent_recipient_unique_id.alias("recipient_parent_duns"),
ts.parent_recipient_name.alias("recipient_parent_name"),
ts.parent_recipient_name_raw.alias("recipient_parent_name_raw"),
ts.recipient_location_country_code.alias("recipient_country"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ def object_class_program_activity_df(spark: SparkSession) -> DataFrame:
"obligations_undelivered_orders_unpaid_total"
),
fabpaoc.obligations_delivered_orders_unpaid_total_cpe.alias("obligations_delivered_orders_unpaid_total"),
fabpaoc.obligations_delivered_orders_unpaid_total_cpe.alias(
fabpaoc.obligations_delivered_orders_unpaid_total_fyb.alias(
"obligations_delivered_orders_unpaid_total_FYB"
),
fabpaoc.gross_outlays_undelivered_orders_prepaid_total_cpe.alias(
"gross_outlays_undelivered_orders_prepaid_total"
),
fabpaoc.gross_outlays_undelivered_orders_prepaid_total_cpe.alias(
fabpaoc.gross_outlays_undelivered_orders_prepaid_total_fyb.alias(
"gross_outlays_undelivered_orders_prepaid_total_FYB"
),
fabpaoc.gross_outlays_delivered_orders_paid_total_fyb.alias(
Expand Down
29 changes: 21 additions & 8 deletions usaspending_api/download/filestreaming/download_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def parse_source( # noqa: PLR0913
wait_for_process(zip_process, start_time, download_job)
download_job.save()
except Exception as e:
raise e
raise e from Exception
finally:
# Remove temporary files
os.close(temp_file)
Expand Down Expand Up @@ -760,20 +760,24 @@ def apply_annotations_to_sql(
# In the upgrade to Django 4.2 it was found that the change from psycopg2 to 3 by Django resulted in some
# breaking changes for they way we manage our downloads. In this particular change the GROUP BY was changed to
# now reference annotated fields by their column position. The download logic handles repositioning columns
# into the order that is expected and thus breaks the use of positional reference by the GROUP BY. In order to
# into the order that is expected and thus breaks the use of positional reference used for GROUP BY. In order to
# continue processing downloads in a similar way, the logic below was updated to replace the positional value with
# the annotated value found in the column, allowing the SQL query to work as expected regardless of column order.
group_by_to_replace = []

for idx, val in aliased_list:
split_string = _top_level_split(val, " AS ")
alias = split_string[1].replace('"', "").replace(",", "").strip()
if alias not in aliases:
raise Exception(f'alias "{alias}" not found!')
col_select = split_string[0]
deriv_dict[alias] = col_select
if annotated_group_by_columns and alias in annotated_group_by_columns:
group_by_to_replace.append((idx, col_select))
if alias in aliases:
deriv_dict[alias] = col_select
if annotated_group_by_columns and alias in annotated_group_by_columns:
group_by_to_replace.append((idx, col_select))
else:
# Django 5.2 emits an "AS <query_path>" alias on every values()-projected field
# (e.g. "treasury_account__funding_toptier_agency__name"). The query path is not a caller-known alias, so
# strip it and use the expression just like a direct SELECT in older Django
selects_list.append(col_select.strip())

if group_by_to_replace:
first_half_query, second_half_query = _top_level_split(raw_query, " GROUP BY ")
Expand All @@ -782,7 +786,16 @@ def apply_annotations_to_sql(
# It is assumed that all non-positional values in the GROUP BY are column names meaning the first number
# matching the value of "idx" will be the position. However, this is not guaranteed in the rest of the
# query, so we make sure to stop after the first match found.
second_half_query = second_half_query.replace(f" {idx}", f" {{idx_{idx}}}", 1)
# 1. check if number in second half followed by comma
# 2. if not found, check to see if last item is number
# 3. replace the number at the given index
idx_location = second_half_query.find(f" {idx},")
if idx_location != -1:
second_half_query = second_half_query.replace(f" {idx},", f" {{idx_{idx}}},", 1)
elif second_half_query.startswith(f"{idx},"):
second_half_query = second_half_query.replace(f"{idx},", f" {{idx_{idx}}},", 1)
elif second_half_query.endswith(f" {idx}"):
second_half_query = second_half_query[:-1 * len(f" {idx}")] + f" {{idx_{idx}}}"
second_half_query = second_half_query.format(
**{f"idx_{idx}": col_select for idx, col_select in group_by_to_replace}
)
Expand Down
Loading
Loading