Repository navigation
Speed up the project access check for units - #1897
Open
samanrassam wants to merge 1 commit into
Open
samanrassam wants to merge 1 commit into
samanrassam wants to merge 1 commit into
Conversation
… ID check once, instead of iterating through all projects). Removed extranous check in project_schemas.py and added one test.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1897 +/- ##
=======================================
Coverage 92.88% 92.89%
=======================================
Files 30 30
Lines 5077 5080 +3
=======================================
+ Hits 4716 4719 +3
Misses 361 361 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
samanrassam
marked this pull request as ready for review
November 28, 2026 00:29
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.
Pull Request Template
Before Marking as Ready for Review
dev(or other targeted branch)SPRINTLOG.mdif neededIf the target branch is
master:Summary
Bulk uploads from large units caused CPU spikes on the backend, because the project access check loaded every project in the user's unit on each request, so once for every uploaded file. The check now only looks at the project's unit, the user's
ProjectUsersrow or the Super Admin role. This gives the same answer as before without loading any project lists. The error is also unchanged (403, "Project access denied."), so the CLI is not affected. With ~3k projects in the unit, the load took a median of 39 ms on dev and 1 ms on this branch.utils.py:
verify_project_accessused to checkproject in current_user.projects. For a unit user that list is every project the unit has ever had, inactive ones included, and for a Super Admin it is every project in DDS. It now comparesproject.unit_idwith the user'sunit_idfor Unit Admins and Unit Personnel, looks up the oneProjectUsersrow for the project and user for Researchers (Project Owners included). We have the same behavior as before with always allowing Super Admins.unit.projectsis defined byProject.unit_id, so the unit check gives the same result as the old list. Any other role is denied.project_schemas.py:
verify_project_accesshere was an identical copy of the one inutils.py, and it was the one uploads went through, viaProjectRequiredSchema. It is removed andProjectRequiredSchemanow calls theutils.pyversion, so the fix applies to every endpoint and there is only one access check to keep up to date. This duplication was added in #1240.test_utils.py:
test_verify_project_access_no_unitchecks that a unit user is denied access to a project without a unit (unit_idis NULL). This is the one case where comparingunit_idcould give a different answer than the old list, and no existing test covered it. Unit users inside and outside the unit, researchers in and not in the project, and Super Admins are already covered by existing tests intests/test_utils.py,tests/test_project_info.pyandtests/test_project_listing.py.Related Issue/Ticket
HMS-2714, from the investigation in HMS-2712.
Testing
Locally the full test suite passes (946 passed) and formatter is clean.
I also counted the queries
ProjectRequiredSchema().load()runs on dev and on this branch. As a unit user it no longer loads the unit and its projects, as a Super Admin it no longer loads all projects, and as a researcher it looks up oneProjectUsersrow instead of all of theirs. With ~3k projects in the unit, the load took a median of 39 ms on dev and 1 ms on this branch.Reviewer Notes
It was brought up during a discussion that the password reset mechanism might revoke access that interferes with the ID check in this PR.
A password reset only deletes the user's
ProjectUserKeysand key pair, not theirProjectUsersrows orunit_id, so this check gives the same answer before and after a reset. Downloads after a reset are still stopped byverify_project_user_key.Once all boxes are checked, mark the PR as Ready for Review and tag at least one team member as the initial reviewer.