-
Notifications
You must be signed in to change notification settings - Fork 86
[ENG-871] Addresses circular import and cleans up some tests #6383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENG-871] Addresses circular import and cleans up some tests #6383
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
@@ -1,4 +1,4 @@ | |||
from typing import Any, Dict, List, Optional | |||
from typing import Any, Optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My crusade to replace List, Dict with the built ins to reduce imports continues 😂
@@ -111,67 +110,65 @@ def access_request(self, *inputs: List[Row]) -> List[Row]: | |||
def _ensure_manual_task_instances( | |||
self, | |||
db: Session, | |||
manual_tasks: List[ManualTask], | |||
manual_task: ManualTask, | |||
privacy_request: PrivacyRequest, | |||
allowed_config_type: "ManualTaskConfigurationType", | |||
) -> None: | |||
"""Create ManualTaskInstances for configs matching `allowed_config_type` if they don't exist.""" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Able to un-nest this function because we are only looking at one ManualTask at a time.
@@ -182,79 +179,74 @@ def _format_size(size_bytes: int) -> str: | |||
size /= 1024.0 | |||
return f"{size:.1f} PB" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Able to un-nest this function because we are only looking at one ManualTask at a time.
|
||
# TYPE_CHECKING import placed after all runtime imports to avoid lint issues | ||
if TYPE_CHECKING: # pragma: no cover | ||
from fides.api.graph.traversal import TraversalNode # noqa: F401 | ||
from fides.api.models.policy import Policy # noqa: F401 | ||
|
||
|
||
class ManualTaskAddress: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to it separate module to remove circular imports
@@ -98,26 +56,20 @@ def get_manual_task_addresses(db: Session) -> List[CollectionAddress]: | |||
return manual_task_addresses | |||
|
|||
|
|||
def get_manual_tasks_for_connection_config( | |||
def get_manual_task_for_connection_config( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connection_config
and manual_task
have a 1:1 unique relationship so we will always be getting just one ManualTask from this query. Updated naming and usage across files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a question, do we enforce uniqueness at the DB level, or just at the application level ? If we do it at the app level can we maybe add a warning if we find more than one?
also I think we might want to use something like one_or_none
in the query rather than first
-- this makes it super clear that we only ever expect a single result there and it will actually error if it finds more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -130,24 +82,23 @@ def create_manual_data_traversal_node( | |||
connection_key = address.dataset | |||
|
|||
# Get manual tasks for this connection to determine fields | |||
manual_tasks = get_manual_tasks_for_connection_config(db, connection_key) | |||
manual_task = get_manual_task_for_connection_config(db, connection_key) | |||
|
|||
# Create fields based on ManualTaskConfigFields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Able to un-nest here as well.
# Create Node and TraversalNode (import locally to avoid cyclic import) | ||
from fides.api.graph.traversal import TraversalNode # local import | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
|
||
# Manual task collections act as root nodes - they don't need identity dependencies | ||
# since they provide manually-entered data rather than consuming identity data. | ||
for manual_task in manual_tasks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Able to un-nest this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the various task tests for Manual Tasks into the same dir and consolidated the fixtures to this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was also moved, but due to some removal of outdated tests and other changes it is a big enough change to look like a whole new file.
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (76.28%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #6383 +/- ##
==========================================
+ Coverage 86.80% 86.98% +0.18%
==========================================
Files 453 454 +1
Lines 28907 28909 +2
Branches 3215 3211 -4
==========================================
+ Hits 25092 25146 +54
+ Misses 3095 3046 -49
+ Partials 720 717 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the cleanup, this was such a nice PR to review 😌 Remember to add the changelog entry; also I left a suggestion in a comment.
Haven't tested manually but since this is just a refactor and tests are still passing I think that's probably ok?
@@ -98,26 +56,20 @@ def get_manual_task_addresses(db: Session) -> List[CollectionAddress]: | |||
return manual_task_addresses | |||
|
|||
|
|||
def get_manual_tasks_for_connection_config( | |||
def get_manual_task_for_connection_config( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a question, do we enforce uniqueness at the DB level, or just at the application level ? If we do it at the app level can we maybe add a warning if we find more than one?
also I think we might want to use something like one_or_none
in the query rather than first
-- this makes it super clear that we only ever expect a single result there and it will actually error if it finds more
), | ||
], | ||
) | ||
def test_artificial_graphs_filter_by_policy_type( | ||
@pytest.mark.usefixtures("manual_setup") | ||
def test_artificial_graphs_include_all_fields( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did we change what we're testing here? or is the git diff just showing up annoyigly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a change. I am not sure why this test was even passing before. The Graph should create initially with all potential nodes. When the traversal runs and the graph executes is where the filtering actually occurs. I updated this test to follow the correct behavior.
I have been heavily manually testing. I will run through it one more time before merging :) |
fides
|
Project |
fides
|
Branch Review |
main
|
Run status |
|
Run duration | 00m 53s |
Commit |
|
Committer | JadeWibbels |
View all properties for this run ↗︎ |
Test results | |
---|---|
|
0
|
|
0
|
|
0
|
|
0
|
|
5
|
Upgrade your plan to view test results. | |
View all changes introduced in this branch ↗︎ |
Issue ENG-871
Description Of Changes
Due to some speed required to get Manual Tasks up and running some comments on PRs did not have time to be addressed. This PR addresses this one: #6261 (comment) regarding circular imports.
Code Changes
Steps to Confirm
There are no intended changes to functionality. The tests should all pass. For additional functional testing:
Pre-Merge Checklist
CHANGELOG.md
updatedmain
downgrade()
migration is correct and works