Skip to content

Commit

Permalink
fix(data-warehouse): Use database async wrapper (#25971)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 authored Nov 4, 2024
1 parent 0011ba8 commit 571add2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# TODO: remove dependency

from posthog.warehouse.external_data_source.jobs import (
create_external_data_job,
acreate_external_data_job,
)
from posthog.warehouse.models.external_data_schema import (
ExternalDataSchema,
Expand All @@ -27,7 +27,7 @@ async def create_external_data_job_model_activity(inputs: CreateExternalDataJobM
logger = await bind_temporal_worker_logger(team_id=inputs.team_id)

try:
job = await sync_to_async(create_external_data_job)(
job = await acreate_external_data_job(
team_id=inputs.team_id,
external_data_source_id=inputs.source_id,
external_data_schema_id=inputs.schema_id,
Expand Down
6 changes: 3 additions & 3 deletions posthog/temporal/tests/data_imports/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,9 @@ def get_jobs():
return list(jobs)

with mock.patch(
"posthog.temporal.data_imports.workflow_activities.create_job_model.create_external_data_job",
) as mock_list_limited_team_attributes:
mock_list_limited_team_attributes.side_effect = Exception("Ruhoh!")
"posthog.temporal.data_imports.workflow_activities.create_job_model.acreate_external_data_job",
) as acreate_external_data_job:
acreate_external_data_job.side_effect = Exception("Ruhoh!")

with pytest.raises(Exception):
await _execute_run(workflow_id, inputs, stripe_customer["data"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
SyncNewSchemasActivityInputs,
sync_new_schemas_activity,
)
from posthog.warehouse.external_data_source.jobs import create_external_data_job
from posthog.warehouse.external_data_source.jobs import acreate_external_data_job
from posthog.warehouse.models import (
get_latest_run_if_exists,
ExternalDataJob,
Expand Down Expand Up @@ -238,7 +238,7 @@ async def test_update_external_job_activity(activity_environment, team, **kwargs
should_sync=True,
)

new_job = await sync_to_async(create_external_data_job)(
new_job = await acreate_external_data_job(
team_id=team.id,
external_data_source_id=new_source.pk,
workflow_id=activity_environment.info.workflow_id,
Expand Down Expand Up @@ -283,7 +283,7 @@ async def test_update_external_job_activity_with_retryable_error(activity_enviro
should_sync=True,
)

new_job = await sync_to_async(create_external_data_job)(
new_job = await acreate_external_data_job(
team_id=team.id,
external_data_source_id=new_source.pk,
workflow_id=activity_environment.info.workflow_id,
Expand Down Expand Up @@ -329,7 +329,7 @@ async def test_update_external_job_activity_with_non_retryable_error(activity_en
should_sync=True,
)

new_job = await sync_to_async(create_external_data_job)(
new_job = await acreate_external_data_job(
team_id=team.id,
external_data_source_id=new_source.pk,
workflow_id=activity_environment.info.workflow_id,
Expand Down
3 changes: 2 additions & 1 deletion posthog/warehouse/external_data_source/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def get_external_data_source(team_id: str, external_data_source_id: str) -> Exte
return ExternalDataSource.objects.get(team_id=team_id, id=external_data_source_id)


def create_external_data_job(
@database_sync_to_async
def acreate_external_data_job(
external_data_source_id: UUID,
external_data_schema_id: UUID,
workflow_id: str,
Expand Down

0 comments on commit 571add2

Please sign in to comment.