Skip to content

[DEV-15427] Fixed Incorrect Category Field Modification - #4693

Open
DavidMikolaKC wants to merge 20 commits into
qatfrom
bug/dev-15427-use-per-request-category-dataclass
Open

[DEV-15427] Fixed Incorrect Category Field Modification#4693
DavidMikolaKC wants to merge 20 commits into
qatfrom
bug/dev-15427-use-per-request-category-dataclass

Conversation

@DavidMikolaKC

@DavidMikolaKC DavidMikolaKC commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description:

Category is a mutable dataclass (spending_by_category.py:34) instantiated as a class attribute on each concrete view (spending_by_locations.py:189). Line 128 mutates self.category.agg_key in place, and since no per-request self.category = ... exists anywhere except DEFCViewSet's replace() at spending_by_industry_codes.py:143, the mutation hits the class-level singleton shared by all requests on the worker. The mapper is one-way (sub_* keys map to themselves via the default), so one unauthenticated spending_level=subawards POST to /api/v2/search/spending_by_category/county (urls_spending_by_category.py:32) permanently swaps the agg_key, after which transaction/award branches at lines 133-141/205/265 aggregate on the wrong ES field and @cache_response() can persist the bad output.

Technical Details:

Replaced instances of self.category.* fields in the AbstractSpendingByCategoryViewSet to instead create a new instance of the dataclass with the updated fields.

Requirements for PR Merge:

  1. Unit & integration tests updated
  2. API documentation updated (examples listed below)
    1. API Contracts
    2. API UI
    3. Comments
  3. Data validation completed (examples listed below)
    1. Does this work well with the current frontend? Or is the frontend aware of a needed change?
    2. Is performance impacted in the changes (e.g., API, pipeline, downloads, etc.)?
    3. Is the expected data returned with the expected format?
  4. Appropriate Operations ticket(s) created
  5. Jira Ticket(s)
    1. DEV-15427

Explain N/A in above checklist:

@DavidMikolaKC DavidMikolaKC self-assigned this Jul 15, 2026
@DavidMikolaKC DavidMikolaKC added do not merge [PR] shouldn't be merged in progress [ISSUE | PR] being worked labels Jul 15, 2026
@DavidMikolaKC DavidMikolaKC added ready for review [PR] ready to be reviewed in progress [ISSUE | PR] being worked and removed in progress [ISSUE | PR] being worked ready for review [PR] ready to be reviewed labels Jul 16, 2026
@DavidMikolaKC DavidMikolaKC added ready for review [PR] ready to be reviewed and removed do not merge [PR] shouldn't be merged in progress [ISSUE | PR] being worked labels Jul 23, 2026

@zachflanders-frb zachflanders-frb left a comment

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.

Requesting changes to add a _category property to the abstract class. We will need to update all the classes that inherit from this class so ensure that they set the _category property instead of the category property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review [PR] ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants