Skip to content

Commit

Permalink
Setting requires_primary_keys for select connectors + updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed Dec 11, 2024
1 parent 7600ab4 commit dd8a3ad
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/fides/api/service/connectors/base_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,11 @@ def execute_standalone_retrieval_query(

@property
def requires_primary_keys(self) -> bool:
"""Indicates if datasets linked to this connector require primary keys for erasures. Defaults to True."""
"""
Indicates if datasets linked to this connector require primary keys for erasures.
Defaults to True.
"""

# Defaulting to true for now so we can keep the default behavior and
# incrementally determine the need for primary keys across all connectors
return True
1 change: 1 addition & 0 deletions src/fides/api/service/connectors/bigquery_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BigQueryConnector(SQLConnector):

@property
def requires_primary_keys(self) -> bool:
"""BigQuery does not have the concept of primary keys so they're not required for erasures."""
return False

# Overrides BaseConnector.build_uri
Expand Down
5 changes: 5 additions & 0 deletions src/fides/api/service/connectors/postgres_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class PostgreSQLConnector(SQLConnector):

secrets_schema = PostgreSQLSchema

@property
def requires_primary_keys(self) -> bool:
"""Postgres allows arbitrary columns in the WHERE clause for updates so primary keys are not required."""
return False

def build_uri(self) -> str:
"""Build URI of format postgresql://[user[:password]@][netloc][:port][/dbname]"""
config = self.secrets_schema(**self.configuration.secrets or {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def get_update_stmt(
def get_update_clauses(
self,
update_value_map: Dict[str, Any],
non_empty_reference_fields: Dict[str, Field],
where_clause_fields: Dict[str, Field],
) -> List[str]:
"""Returns a list of update clauses for the update statement."""

Expand Down Expand Up @@ -567,7 +567,7 @@ def format_key_map_for_update_stmt(self, param_map: Dict[str, Any]) -> List[str]
def get_update_clauses(
self,
update_value_map: Dict[str, Any],
non_empty_reference_fields: Dict[str, Field],
where_clause_fields: Dict[str, Field],
) -> List[str]:
"""Returns a list of update clauses for the update statement."""
return self.format_key_map_for_update_stmt(update_value_map)
Expand Down
2 changes: 2 additions & 0 deletions src/fides/api/service/connectors/saas_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
class SaaSConnector(BaseConnector[AuthenticatedClient], Contextualizable):
"""A connector type to integrate with third-party SaaS APIs"""

@property
def requires_primary_keys(self) -> bool:
"""SaaS connectors work with HTTP requests, so the database concept of primary keys does not apply."""
return False

def get_log_context(self) -> Dict[LoggerContextKeys, Any]:
Expand Down
5 changes: 5 additions & 0 deletions src/fides/api/service/connectors/scylla_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class ScyllaConnectorMissingKeyspace(Exception):
class ScyllaConnector(BaseConnector[Cluster]):
"""Scylla Connector"""

@property
def requires_primary_keys(self) -> bool:
"""ScyllaDB requires primary keys for erasures."""
return True

def build_uri(self) -> str:
"""
Builds URI - Not yet implemented
Expand Down
11 changes: 8 additions & 3 deletions src/fides/api/service/connectors/scylla_query_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ def format_key_map_for_update_stmt(self, param_map: Dict[str, Any]) -> List[str]
def get_update_clauses(
self,
update_value_map: Dict[str, Any],
non_empty_reference_fields: Dict[str, Field],
where_clause_fields: Dict[str, Field],
) -> List[str]:
"""Returns a list of update clauses for the update statement."""
"""Returns a list of update clauses for the update statement.
Omits primary key fields from updates since ScyllaDB prohibits
updating primary key fields.
"""

return self.format_key_map_for_update_stmt(
{
key: value
for key, value in update_value_map.items()
if key not in non_empty_reference_fields
if key not in where_clause_fields
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dataset:
data_categories: [user.contact.address.street]
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: state
data_categories: [user.contact.address.state]
- name: street
Expand All @@ -36,6 +38,8 @@ dataset:
data_type: string
- name: id
data_categories: [user.unique_id]
fides_meta:
primary_key: True
- name: name
data_categories: [user.name]
fides_meta:
Expand All @@ -58,6 +62,8 @@ dataset:
data_type: string
- name: id
data_categories: [user.unique_id]
fides_meta:
primary_key: True
- name: name
data_categories: [user.name]
fides_meta:
Expand All @@ -74,6 +80,8 @@ dataset:
direction: from
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: time
data_categories: [user.sensor]

Expand All @@ -88,6 +96,8 @@ dataset:
direction: from
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: shipping_address_id
data_categories: [system.operations]
fides_meta:
Expand Down Expand Up @@ -138,6 +148,8 @@ dataset:
direction: from
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: name
data_categories: [user.financial]
- name: preferred
Expand All @@ -147,6 +159,8 @@ dataset:
fields:
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: name
data_categories: [system.operations]
- name: price
Expand All @@ -161,6 +175,8 @@ dataset:
data_type: string
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: month
data_categories: [system.operations]
- name: name
Expand Down Expand Up @@ -193,6 +209,8 @@ dataset:
direction: from
- name: id
data_categories: [system.operations]
fides_meta:
primary_key: True
- name: opened
data_categories: [system.operations]

Expand Down
Loading

0 comments on commit dd8a3ad

Please sign in to comment.