Skip to content

Commit

Permalink
make sure to call distinct on team ids
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE committed Aug 5, 2024
1 parent e79bcf4 commit 733d282
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
25 changes: 25 additions & 0 deletions posthog/tasks/test/test_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
check_synced_row_limits_of_team,
capture_workspace_rows_synced_by_team,
validate_data_warehouse_table_columns,
capture_external_data_rows_synced,
)
from posthog.warehouse.models import ExternalDataSource, ExternalDataJob
from freezegun import freeze_time
Expand Down Expand Up @@ -171,3 +172,27 @@ def test_validate_data_warehouse_table_columns(self, mock_get_ph_client: MagicMo
assert table.columns.get("some_columns").get("valid") is True
mock_ph_client.capture.assert_called_once()
mock_ph_client.shutdown.assert_called_once()

@patch("posthog.tasks.warehouse.capture_workspace_rows_synced_by_team.delay")
def test_capture_external_data_rows_synced(self, mock_capture_workspace_rows_synced_by_team: MagicMock) -> None:
ExternalDataSource.objects.create(
source_id="test_id",
connection_id="fake connectino_id",
destination_id="fake destination_id",
team=self.team,
status="Running",
source_type="Stripe",
)

ExternalDataSource.objects.create(
source_id="another_id",
connection_id="fake connectino_id",
destination_id="fake destination_id",
team=self.team,
status="Running",
source_type="Stripe",
)

capture_external_data_rows_synced()

assert mock_capture_workspace_rows_synced_by_team.call_count == 1
8 changes: 5 additions & 3 deletions posthog/tasks/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

def capture_external_data_rows_synced() -> None:
# the teams that are not demo and not internal metrics of existing sources
team_ids = ExternalDataSource.objects.filter(
~Q(team__is_demo=True) & ~Q(team__organization__for_internal_metrics=True)
).values_list("team", flat=True)
team_ids = (
ExternalDataSource.objects.filter(~Q(team__is_demo=True) & ~Q(team__organization__for_internal_metrics=True))
.values_list("team", flat=True)
.distinct()
)
for team_id in team_ids:
capture_workspace_rows_synced_by_team.delay(team_id)

Expand Down

0 comments on commit 733d282

Please sign in to comment.