#3761 : Update createfederalportfolio script match fed agency [dg] #3941
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.
Ticket
Resolves #3761
Changes
create_suborganizations() - Now uses fuzzy matching for both domains and requests
update_domains() - Enhanced to find domain information records via fuzzy org name matching
update_requests() - Enhanced to find domain requests via fuzzy org name matching + shows detailed change preview
--fuzzy_threshold parameter - Configurable similarity threshold (default 85%)
--dry_run flag - Shows exactly what records would be created/updated with before/after values
Context for reviewers
A little bit of background as to what the script does because it is a bit unwieldy:
Previously, the script only matched requests that had federal_agency pointing to the target agency, missing requests where:
Organization name was e.g. "Department of State" but federal_agency something else
Organization name was "U.S. Department of State" but agency was stored as "Department of State"
Now, it finds requests by:
Direct relationship: federal_agency = target_agency
Name matching: organization_name matches any variant of the agency name (per the threshold set on fuzzy matches)
Normalization: All comparisons use normalized strings for consistent matching
Setup
To test locally assure you have good test data by editing some org names tied to your test portfolio / agency used for testing. I used DOS in my tests:
$ docker compose up
Open another terminal or run ^ in the background to test the commands below:
cd to /src
Preview what would change
$ docker compose exec app ./manage.py create_federal_portfolio --agency_name "Department of State" --parse_requests --dry_run --debug
Test with a higher threshold:
$ docker exec ./manage.py create_federal_portfolio --agency_name "Department of State" --parse_requests --dry_run --fuzzy_threshold 95
Code Review Verification Steps
As the original developer, I have
Satisfied acceptance criteria and met development standards
Ensured code standards are met (Original Developer)
Validated user-facing changes (if applicable)
As a code reviewer, I have
Reviewed, tested, and left feedback about the changes
Validated user-facing changes as a developer
Note: Multiple code reviewers can share the checklists above, a second reviewer should not make a duplicate checklist. All checks should be checked before approving, even those labeled N/A.
As a designer reviewer, I have
Verified that the changes match the design intention
Validated user-facing changes as a designer
References
Screenshots