[DEV-15427] Fixed Incorrect Category Field Modification - #4693
Open
DavidMikolaKC wants to merge 20 commits into
Open
[DEV-15427] Fixed Incorrect Category Field Modification#4693DavidMikolaKC wants to merge 20 commits into
DavidMikolaKC wants to merge 20 commits into
Conversation
zachflanders-frb
requested changes
Jul 24, 2026
zachflanders-frb
left a comment
Contributor
There was a problem hiding this comment.
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.
…pending-api into bug/dev-15427-use-per-request-category-dataclass
…pending-api into bug/dev-15427-use-per-request-category-dataclass
…tps://github.com/fedspendingtransparency/usaspending-api into bug/dev-15427-use-per-request-category-dataclass
…tps://github.com/fedspendingtransparency/usaspending-api into bug/dev-15427-use-per-request-category-dataclass
…tps://github.com/fedspendingtransparency/usaspending-api into bug/dev-15427-use-per-request-category-dataclass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Explain N/A in above checklist: