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

Remove project from DeleteSource table in shredder_targets #6573

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bigquery_etl/shredder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class DeleteSource:
project: str = SHARED_PROD
conditions: tuple[str, ...] = ()

def __post_init__(self):
"""Validate the table string."""
if len(self.table.split(".")) != 2:
raise ValueError(
"DeleteSource table must be in the 'dataset.table' format."
)

@property
def table_id(self):
"""Table Id."""
Expand All @@ -55,6 +62,13 @@ class DeleteTarget:
field: str | tuple[str, ...]
project: str = SHARED_PROD

def __post_init__(self):
"""Validate the table string."""
if len(self.table.split(".")) != 2:
raise ValueError(
"DeleteTarget table must be in the 'dataset.table' format."
)

@property
def table_id(self):
"""Table Id."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ def get_associated_deletions(
stable_table_ref.dataset_id[: -len("_stable")]
in glean_channel_names
):
deletion_request_table = (
f"{stable_table_ref.project}.{stable_table_ref.dataset_id}.deletion_request_v1"
)
if table_exists(client, deletion_request_table):
if table_exists(
client,
f"{stable_table_ref.project}.{stable_table_ref.dataset_id}.deletion_request_v1",
):
table_to_deletions[stable_table] = {
DeleteSource(
table=deletion_request_table,
table=f"{stable_table_ref.dataset_id}.deletion_request_v1",
field=GLEAN_CLIENT_ID,
project=SHARED_PROD,
)
Expand Down
47 changes: 47 additions & 0 deletions tests/shredder/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from multiprocessing.pool import ThreadPool
from unittest import mock

import pytest
from google.api_core.exceptions import NotFound
from google.cloud import bigquery
from google.cloud.bigquery import DatasetReference
Expand Down Expand Up @@ -419,3 +420,49 @@ def test_delete_target_fields_match_sources():
f"Invalid delete target for {target.table}: number of fields in target "
f"(found {field_count}) must match number of sources (found {source_count})"
)


def test_delete_source_invalid():
"""DeleteSource constructor should fail when the given table is invalid."""
DeleteSource(
table="dataset.deletion_request_v1",
field="client_id",
project="project",
)

with pytest.raises(ValueError):
DeleteSource(
table="deletion_request_v1",
field="client_id",
project="project",
)

with pytest.raises(ValueError):
DeleteSource(
table="project.dataset.deletion_request_v1",
field="client_id",
project="project",
)


def test_delete_target_invalid():
"""DeleteTarget constructor should fail when the given table is invalid."""
DeleteTarget(
table="dataset.deletion_request_v1",
field="client_id",
project="project",
)

with pytest.raises(ValueError):
DeleteTarget(
table="deletion_request_v1",
field="client_id",
project="project",
)

with pytest.raises(ValueError):
DeleteTarget(
table="project.dataset.deletion_request_v1",
field="client_id",
project="project",
)