Skip to content

Commit

Permalink
Merge branch 'main' into field_level_masking
Browse files Browse the repository at this point in the history
  • Loading branch information
Linker44 committed Nov 7, 2024
2 parents 0b13cdf + 1847185 commit 55f627e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 49 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ The types of changes are:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [Unreleased](https://github.com/ethyca/fideslang/compare/3.0.7...main)
## [Unreleased](https://github.com/ethyca/fideslang/compare/3.0.8...main)

- Add field-level masking strategy overrides [#23](https://github.com/ethyca/fideslang/pull/23)

## [3.0.8](https://github.com/ethyca/fideslang/compare/3.0.7...3.0.8)

### Changed

- Remove stipulation that sub fields (Field) of a Field object cannot have data categories assigned [#22](https://github.com/ethyca/fideslang/pull/22)

## [3.0.7](https://github.com/ethyca/fideslang/compare/3.0.6...3.0.7)

### Added
Expand Down
1 change: 0 additions & 1 deletion src/fideslang/default_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
2. Copy/Paste the JSON response below
"""


COUNTRY_CODES = [
{"name": "Afghanistan", "alpha3Code": "AFG"},
{"name": "Åland Islands", "alpha3Code": "ALA"},
Expand Down
4 changes: 2 additions & 2 deletions src/fideslang/default_taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .data_uses import DEFAULT_DATA_USES
from .organizations import DEFAULT_ORGANIZATIONS

sort_data_types = (
lambda x: x.parent_key if hasattr(x, "parent_key") and x.parent_key else x.fides_key
sort_data_types = lambda x: (
x.parent_key if hasattr(x, "parent_key") and x.parent_key else x.fides_key
)

DEFAULT_TAXONOMY = Taxonomy(
Expand Down
1 change: 1 addition & 0 deletions src/fideslang/manifests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module handles anything related to working with raw manifest files."""

import glob
from functools import reduce
from typing import Dict, List, Set, Union
Expand Down
5 changes: 0 additions & 5 deletions src/fideslang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ def validate_object_fields(
) -> DatasetField:
"""Two validation checks for object fields:
- If there are sub-fields specified, type should be either empty or 'object'
- Additionally object fields cannot have data_categories.
"""
fields = self.fields
declared_data_type = None
Expand All @@ -505,10 +504,6 @@ def validate_object_fields(
f"The data type '{data_type}' on field '{field_name}' is not compatible with specified sub-fields. Convert to an 'object' field."
)

if (fields or declared_data_type == "object") and self.data_categories:
raise ValueError(
f"Object field '{field_name}' cannot have specified data_categories. Specify category on sub-field instead"
)
return self


Expand Down
1 change: 1 addition & 0 deletions src/fideslang/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module handles everything related to parsing resources into Pydantic models,
either from local files or the server.
"""

from typing import Dict, List

from fideslang import FidesModel, Taxonomy, model_map
Expand Down
1 change: 1 addition & 0 deletions src/fideslang/validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains all of the additional validation for the resource models.
"""

import re
from collections import Counter
from typing import Annotated, Dict, List, Optional, Pattern, Set, Tuple
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common fixtures to be used across tests."""

import os
from typing import Any, Dict

Expand Down
81 changes: 41 additions & 40 deletions tests/fideslang/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,59 +717,61 @@ def test_return_all_elements_on_array_field(self):
)

def test_data_categories_at_object_level(self):
with pytest.raises(ValidationError) as exc:
DatasetField(
name="test_field",
data_categories=["user"],
fides_meta=FidesMeta(
references=None,
identify=None,
primary_key=False,
data_type="object",
length=None,
return_all_elements=None,
read_only=None,
),
fields=[DatasetField(name="nested_field")],
)
assert_error_message_includes(
exc, "Object field 'test_field' cannot have specified data_categories"
)

def test_object_field_conflicting_types(self):
with pytest.raises(ValidationError) as exc:
DatasetField(
name="test_field",
data_categories=["user"],
fides_meta=FidesMeta(
references=None,
identify=None,
primary_key=False,
data_type="string",
length=None,
return_all_elements=None,
read_only=None,
),
fields=[DatasetField(name="nested_field")],
)
assert_error_message_includes(
exc, "The data type 'string' on field 'test_field' is not compatible with"
field = DatasetField(
name="test_field",
data_categories=["user"],
fides_meta=FidesMeta(
references=None,
identify=None,
primary_key=False,
data_type="object",
length=None,
return_all_elements=None,
read_only=None,
),
fields=[DatasetField(name="nested_field")],
)

assert field
assert field.data_categories == ["user"]
assert field.fides_meta.data_type == "object"

def test_data_categories_on_nested_fields(self):
DatasetField(
name="test_field",

field = DatasetField(
name="test_for_nest",
data_categories=["user"],
fides_meta=FidesMeta(
references=None,
identify=None,
primary_key=False,
data_type="object",
length=None,
return_all_elements=None,
read_only=None,
),
fields=[DatasetField(name="nested_field", data_categories=["user"])],
fields=[
DatasetField(
name="nested_field",
data_categories=["user"],
fides_meta=FidesMeta(
references=None,
identify=None,
primary_key=False,
data_type="string",
length=None,
read_only=None,
data_categories=["user"],
),
)
],
)

assert field
assert field.data_categories == ["user"]
assert field.fields[0].data_categories == ["user"]


class TestCollectionMeta:
def test_invalid_collection_key(self):
Expand Down Expand Up @@ -806,7 +808,6 @@ def test_erase_after(self):
assert meta.erase_after == [FidesCollectionKey("test_dataset.test_collection")]



class TestAnyUrlString:
def test_valid_url(self):
assert AnyUrlString("https://www.example.com/")
Expand Down

0 comments on commit 55f627e

Please sign in to comment.