diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c5311f..e23bef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ The types of changes are: ## [Unreleased](https://github.com/ethyca/fideslang/compare/3.0.7...main) +### 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) diff --git a/src/fideslang/default_fixtures.py b/src/fideslang/default_fixtures.py index 9838a83..c8f9a4b 100644 --- a/src/fideslang/default_fixtures.py +++ b/src/fideslang/default_fixtures.py @@ -9,7 +9,6 @@ 2. Copy/Paste the JSON response below """ - COUNTRY_CODES = [ {"name": "Afghanistan", "alpha3Code": "AFG"}, {"name": "Ă…land Islands", "alpha3Code": "ALA"}, diff --git a/src/fideslang/default_taxonomy/__init__.py b/src/fideslang/default_taxonomy/__init__.py index b032904..6b16070 100644 --- a/src/fideslang/default_taxonomy/__init__.py +++ b/src/fideslang/default_taxonomy/__init__.py @@ -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( diff --git a/src/fideslang/manifests.py b/src/fideslang/manifests.py index 60143a0..8868ffc 100644 --- a/src/fideslang/manifests.py +++ b/src/fideslang/manifests.py @@ -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 diff --git a/src/fideslang/models.py b/src/fideslang/models.py index bb15f25..2310dfa 100644 --- a/src/fideslang/models.py +++ b/src/fideslang/models.py @@ -478,7 +478,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 @@ -494,10 +493,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 diff --git a/src/fideslang/parse.py b/src/fideslang/parse.py index 9c1a25c..27d04fd 100644 --- a/src/fideslang/parse.py +++ b/src/fideslang/parse.py @@ -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 diff --git a/src/fideslang/validation.py b/src/fideslang/validation.py index 9c1639c..74c3c46 100644 --- a/src/fideslang/validation.py +++ b/src/fideslang/validation.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 2f177e9..142c021 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """Common fixtures to be used across tests.""" + import os from typing import Any, Dict diff --git a/tests/fideslang/test_validation.py b/tests/fideslang/test_validation.py index d14c145..f7fe122 100644 --- a/tests/fideslang/test_validation.py +++ b/tests/fideslang/test_validation.py @@ -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): @@ -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/")