Skip to content
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

HJ-20 remove requirement in fides and fideslang to not have datacategories on subfields #5434

Merged
merged 7 commits into from
Nov 7, 2024
Merged
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ The types of changes are:
## [Unreleased](https://github.com/ethyca/fidesplus/compare/2.49.0...main)




## [2.49.0](https://github.com/ethyca/fidesplus/compare/2.48.2...2.49.0)

### Added
Expand All @@ -31,6 +29,7 @@ The types of changes are:
- Added a security setting that must be set to true to enable the access request download feature [#5451](https://github.com/ethyca/fides/pull/5451)
- Preventing erasures for the Zendesk integration if there are any open tickets [#5429](https://github.com/ethyca/fides/pull/5429)
- Updated look/feel of all badges in the Data map report [#5464](https://github.com/ethyca/fides/pull/5464)
- Allow adding data categories to nested fields [#5434](https://github.com/ethyca/fides/pull/5434)

### Fixed
- Fix rendering of subfield names in D&D tables [#5439](https://github.com/ethyca/fides/pull/5439)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ types-defusedxml==0.7.0.20240218
expandvars==0.9.0
fastapi[all]==0.111.0
fastapi-pagination[sqlalchemy]==0.12.25
fideslang==3.0.7
fideslog==1.2.10
firebase-admin==5.3.0
GitPython==3.1.41
Expand Down Expand Up @@ -72,3 +71,4 @@ twilio==7.15.0
typing-extensions==4.12.2
validators==0.20.0
versioneer==0.19
fideslang==3.0.8
16 changes: 0 additions & 16 deletions src/fides/api/graph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,6 @@ class ObjectField(Field):

fields: Dict[str, Field]

@field_validator("data_categories")
@classmethod
def validate_data_categories(
cls, value: Optional[List[FidesKey]]
) -> Optional[List[FidesKey]]:
"""To prevent mismatches between data categories on an ObjectField and a nested ScalarField, only
allow data categories to be defined on the individual fields.

This shouldn't be hit unless an ObjectField is declared directly.
"""
if value:
raise ValueError(
"ObjectFields cannot be given data_categories; annotate the sub-fields instead."
)
return value

def cast(self, value: Dict[str, Any]) -> Optional[Dict[str, Any]]:
"""Cast the input value into the form represented by data_type."""

Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,26 @@ def resources_dict():
path="another.another.path",
data_categories=["user.contact.email"],
),
models.DatasetField(
name="address",
description="example top level field for nesting",
path="table.address",
data_categories=["user.contact.address"],
fields=[
models.DatasetField(
name="city",
description="example city field",
path="table.address.city",
data_categories=["user.contact.address.city"],
),
models.DatasetField(
name="state",
description="example state field",
path="table.address.state",
data_categories=["user.contact.address.state"],
),
],
),
],
)
],
Expand Down
30 changes: 15 additions & 15 deletions tests/ops/graph/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,21 +659,21 @@ def test_generate_object_field_with_data_categories(self):
data_categories=["user.contact.address.street"],
)

with pytest.raises(pydantic.ValidationError):
generate_field(
name="obj",
data_categories=["A.B.C"],
identity="identity",
data_type_name="object",
references=[],
is_pk=False,
length=0,
is_array=False,
sub_fields=[apt_no_sub_field],
return_all_elements=None,
read_only=False,
custom_request_field=None,
)
field = generate_field(
name="obj",
data_categories=["A.B.C"],
identity="identity",
data_type_name="object",
references=[],
is_pk=False,
length=0,
is_array=False,
sub_fields=[apt_no_sub_field],
return_all_elements=None,
read_only=False,
custom_request_field=None,
)
assert field

def test_generate_read_only_scalar_field(self):
field = generate_field(
Expand Down
36 changes: 14 additions & 22 deletions tests/ops/util/test_dataset_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
example_dataset_yaml = """dataset:
- fides_key: xyz
fidesops_meta:
after: [db1, db2, db3]
after: [db1, db2, db3]
name: xyz
description: x
collections:
Expand All @@ -29,11 +29,11 @@
after: [a.b, c.d, e.f]
fields:
- name: city
data_categories: [user.contact.address.city]
data_categories: [user.contact.address.city]
- name: id
data_categories: [system.operations]
fidesops_meta:
primary_key: True
primary_key: True
data_type: integer
"""

Expand Down Expand Up @@ -63,7 +63,7 @@
data_type: string
- name: submitter
fidesops_meta:
data_type: string
data_type: string
data_categories: [user]
- name: thumbnail
fields:
Expand Down Expand Up @@ -293,32 +293,24 @@ def test_dataset_graph_connected_by_nested_fields():


example_object_with_data_categories_nested_yaml = """dataset:
- fides_key: mongo_nested_test
- fides_key: mongo_nested_test
name: Mongo Example Nested Test Dataset
description: Example of a Mongo dataset that has a data_category incorrectly declared at the object level
collections:
- name: photos
fields:
- name: thumbnail
data_categories: [user]
data_categories: [user]
fidesops_meta:
data_type: object
fields:
- name: photo_id
data_type: integer
- name: name
data_categories: [user]
data_categories: [user]
"""


def test_object_data_category_validation():
"""Test trying to validate object with data category specified"""
with pytest.raises(ValidationError):
Dataset.model_validate(
__to_dataset__(example_object_with_data_categories_nested_yaml)
)


non_array_field_with_invalid_flag = """dataset:
- fides_key: mongo_return_all_elements_test
name: Mongo Return All Elements Test Dataset
Expand All @@ -334,7 +326,7 @@ def test_object_data_category_validation():
- name: photo_id
data_type: integer
- name: name
data_categories: [user]
data_categories: [user]
"""


Expand All @@ -345,7 +337,7 @@ def test_return_all_elements_specified_on_non_array_field():


skip_processing_yaml = """dataset:
- fides_key: a_dataset
- fides_key: a_dataset
name: a_dataset
description: a description
collections:
Expand All @@ -354,19 +346,19 @@ def test_return_all_elements_specified_on_non_array_field():
skip_processing: True
fields:
- name: a_field
data_categories: [user.contact.address.city]
data_categories: [user.contact.address.city]
- name: id
data_categories: [system.operations]
- name: b_collection
fields:
- name: b_field
data_categories: [user.contact.address.city]
data_categories: [user.contact.address.city]
- name: id
data_categories: [system.operations]
"""

skip_processing_invalid_yaml = """dataset:
- fides_key: a_dataset
- fides_key: a_dataset
name: A Dataset
description: a description
collections:
Expand All @@ -375,13 +367,13 @@ def test_return_all_elements_specified_on_non_array_field():
skip_processing: True
fields:
- name: a_field
data_categories: [user.contact.address.city]
data_categories: [user.contact.address.city]
- name: id
data_categories: [system.operations]
- name: b_collection
fields:
- name: b_field
data_categories: [user.contact.address.city]
data_categories: [user.contact.address.city]
- name: id
data_categories: [system.operations]
fides_meta:
Expand Down