Skip to content

Commit e5ef634

Browse files
Fix Key Finding Function (#131)
Fixes a bug where some items were getting mistaken as fides keys.
1 parent b66cd35 commit e5ef634

File tree

6 files changed

+299
-172
lines changed

6 files changed

+299
-172
lines changed

.github/workflows/pr_checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
python_version: ["3.8", "3.9", "3.10", "3.11"]
8585
pydantic_version: ["1.8.2", "1.9.2", "1.10.9"]
8686
runs-on: ubuntu-latest
87+
continue-on-error: true
8788
steps:
8889
- name: Checkout
8990
uses: actions/checkout@v3

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import nox
22

33
nox.options.sessions = []
4+
nox.options.reuse_existing_virtualenvs = True
45

56
TESTED_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
67
TESTED_PYDANTIC_VERSIONS = ["1.8.2", "1.9.2", "1.10.9"]

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ log_level = "DEBUG"
8181
addopts = ["--cov=fideslang",
8282
"--cov-report=term-missing",
8383
"-vv",
84-
"--no-cov-on-fail",
85-
"--disable-pytest-warnings"]
84+
"--no-cov-on-fail",]
8685
markers = [
8786
"unit: only runs tests that don't require non-python dependencies (i.e. a database)",
8887
]

src/fideslang/relationships.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def find_referenced_fides_keys(resource: object) -> Set[FidesKey]:
3535
"""
3636
referenced_fides_keys: Set[FidesKey] = set()
3737

38+
# Str type doesn't have a signature, so we return early
3839
if isinstance(resource, str) and not isinstance(resource, Enum):
39-
return {resource}
40+
return set()
4041

4142
signature = inspect.signature(type(resource), follow_wrapped=True)
4243
attributes = filter(
@@ -59,15 +60,15 @@ def find_referenced_fides_keys(resource: object) -> Set[FidesKey]:
5960
):
6061
nested_keys = find_nested_keys_in_list(attribute_value)
6162
referenced_fides_keys.update(nested_keys)
62-
# If it is an object, recurse this function
63-
elif hasattr(attribute_value, "__dict__"):
63+
# If it is a Pydantic Model then recurse
64+
elif isinstance(attribute_value, BaseModel):
6465
referenced_fides_keys.update(
6566
find_referenced_fides_keys(attribute_value)
6667
)
6768
return referenced_fides_keys
6869

6970

70-
def get_referenced_missing_keys(taxonomy: Taxonomy) -> List[FidesKey]:
71+
def get_referenced_missing_keys(taxonomy: Taxonomy) -> Set[FidesKey]:
7172
"""
7273
Iterate through the Taxonomy and create a set of all of the FidesKeys
7374
that are contained within it.
@@ -80,9 +81,9 @@ def get_referenced_missing_keys(taxonomy: Taxonomy) -> List[FidesKey]:
8081
key_set: Set[FidesKey] = set(
8182
reduce(lambda x, y: set().union(x).union(y), referenced_keys)
8283
)
83-
keys_not_in_taxonomy = [
84+
keys_not_in_taxonomy = {
8485
fides_key
8586
for fides_key in key_set
8687
if get_resource_by_fides_key(taxonomy, fides_key) is None
87-
]
88+
}
8889
return keys_not_in_taxonomy

tests/fideslang/test_models.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
from pytest import deprecated_call, mark, raises
22

3-
from fideslang import DataFlow, Dataset, PrivacyDeclaration, System
4-
from fideslang.models import DatasetCollection, DatasetField
3+
from fideslang import DataFlow, Dataset, Organization, PrivacyDeclaration, System
4+
from fideslang.models import ContactDetails, DatasetCollection, DatasetField
55

66
pytestmark = mark.unit
77

88

9+
class TestOrganization:
10+
def test_valid_organization(self) -> None:
11+
"""Create a standard organization"""
12+
13+
organization = Organization(
14+
fides_key="default_organization",
15+
name="Demo Organization",
16+
description="An e-commerce organization",
17+
security_policy="https://ethyca.com/privacy-policy/",
18+
controller=ContactDetails(
19+
name="Con Troller",
20+
address="123 demo street, New York, NY, USA",
21+
email="controller@demo_company.com",
22+
phone="+1 555 555 5555",
23+
),
24+
data_protection_officer=ContactDetails(
25+
name="DataPro Tection",
26+
address="123 demo street, New York, NY, USA",
27+
email="dpo@demo_company.com",
28+
phone="+1 555 555 5555",
29+
),
30+
representative=ContactDetails(
31+
name="Rep Resentative",
32+
address="123 demo street, New York, NY, USA",
33+
email="representative@demo_company.com",
34+
phone="+1 555 555 5555",
35+
),
36+
fidesctl_meta=None,
37+
)
38+
assert organization
39+
40+
941
class TestDataFlow:
1042
def test_dataflow_valid(self) -> None:
1143
assert DataFlow(

0 commit comments

Comments
 (0)