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

Handle Keys and Collections with a double underscore #3688

Merged
merged 10 commits into from
Jun 30, 2023
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ The types of changes are:

### Fixed
- Render linebreaks in the Fides.js overlay descriptions, etc. [#3665](https://github.com/ethyca/fides/pull/3665)
- Handle names with a double underscore when processing access and erasure requests [#3688](https://github.com/ethyca/fides/pull/3688)
- Broken link to Fides docs site on the About Fides page in Admin UI [#3643](https://github.com/ethyca/fides/pull/3643)

### Developer Experience

### Changed
- Moved GPC preferences slightly earlier in Fides.js lifecycle [#3561](https://github.com/ethyca/fides/pull/3561)

Expand Down
1 change: 1 addition & 0 deletions src/fides/api/task/graph_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ def get_cached_data_for_erasures(
value_dict = cache.get_encoded_objects_by_prefix(
f"PLACEHOLDER_RESULTS__{privacy_request_id}"
)
# TODO: Determine if this requires handling as well
SteveDMurphy marked this conversation as resolved.
Show resolved Hide resolved
return {k.split("__")[-1]: v for k, v in value_dict.items()}


Expand Down
19 changes: 17 additions & 2 deletions src/fides/api/task/task_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ def get_all_cached_objects(self) -> Dict[str, Optional[List[Row]]]:
f"{self.request.id}__access_request"
)
# extract request id to return a map of address:value
return {k.split("__")[-1]: v for k, v in value_dict.items()}
return {self.extract_key_for_address(k): v for k, v in value_dict.items()}

def extract_key_for_address(self, full_request_id: str) -> str:
"""
Handles extracting the correct Dataset:Collection to map to extracted
values.

Handles an edge case where double underscores exist in either the fides_key
of the Dataset or the Collection name.
"""
request_id_dataset, collection = full_request_id.split(":")
number_of_expected_items_to_remove = 2
request_list = request_id_dataset.split("__")
address_list = request_list[number_of_expected_items_to_remove:]
dataset = "__".join(address_list)
SteveDMurphy marked this conversation as resolved.
Show resolved Hide resolved
return f"{dataset}:{collection}"

def cache_erasure(self, key: str, value: int) -> None:
"""Cache that a node's masking is complete. Object will be stored in redis under
Expand All @@ -163,7 +178,7 @@ def get_all_cached_erasures(self) -> Dict[str, int]:
f"{self.request.id}__erasure_request"
)
# extract request id to return a map of address:value
return {k.split("__")[-1]: v for k, v in value_dict.items()} # type: ignore
return {self.extract_key_for_address(k): v for k, v in value_dict.items()} # type: ignore

def write_execution_log( # pylint: disable=too-many-arguments
self,
Expand Down
7 changes: 7 additions & 0 deletions tests/ops/task/test_task_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def test_cache_object(self, db, privacy_request, policy, integration_manual_conf
"access_request__postgres_example:payment",
[{"id": 2, "ccn": "111-111-1111-1111", "customer_id": 1}],
)
resources.cache_object(
"access_request__postgres__double__underscore__example:double__underscore__collection",
[{"id": 3, "last_name": "Doe"}],
)
resources.cache_erasure("manual_example:filing-cabinet", 2)

# Only access results from "cache_object" are returned
Expand All @@ -24,6 +28,9 @@ def test_cache_object(self, db, privacy_request, policy, integration_manual_conf
{"id": 2, "ccn": "111-111-1111-1111", "customer_id": 1}
],
"postgres_example:customer": [{"id": 1, "last_name": "Doe"}],
"postgres__double__underscore__example:double__underscore__collection": [
{"id": 3, "last_name": "Doe"}
],
}

def test_cache_erasure(
Expand Down