Skip to content

Commit

Permalink
fix: Fix UUID typing issues (#24815)
Browse files Browse the repository at this point in the history
  • Loading branch information
timgl authored Sep 5, 2024
1 parent 1bf80d4 commit acda90e
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 51 deletions.
2 changes: 1 addition & 1 deletion ee/billing/quota_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def org_quota_limited_until(

if posthoganalytics.feature_enabled(
QUOTA_LIMIT_DATA_RETENTION_FLAG,
organization.id,
str(organization.id),
groups={"organization": str(organization.id)},
group_properties={"organization": {"id": str(organization.id)}},
):
Expand Down
6 changes: 3 additions & 3 deletions ee/billing/test/test_quota_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_quota_limiting_feature_flag_enabled(self, patch_feature_enabled, patch_
quota_limited_orgs, quota_limiting_suspended_orgs = update_all_org_billing_quotas()
patch_feature_enabled.assert_called_with(
QUOTA_LIMIT_DATA_RETENTION_FLAG,
self.organization.id,
str(self.organization.id),
groups={"organization": org_id},
group_properties={"organization": {"id": org_id}},
group_properties={"organization": {"id": str(org_id)}},
)
patch_capture.assert_called_once_with(
org_id,
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_quota_limiting_feature_flag_enabled(self, patch_feature_enabled, patch_
quota_limited_orgs, quota_limiting_suspended_orgs = update_all_org_billing_quotas()
patch_feature_enabled.assert_called_with(
QUOTA_LIMIT_DATA_RETENTION_FLAG,
self.organization.id,
str(self.organization.id),
groups={"organization": org_id},
group_properties={"organization": {"id": org_id}},
)
Expand Down
2 changes: 1 addition & 1 deletion ee/session_recordings/session_recording_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def modify_recordings(
return response.Response({"success": True})

if request.method == "DELETE":
playlist_item = SessionRecordingPlaylistItem.objects.get(playlist=playlist, recording=session_recording_id) # type: ignore
playlist_item = SessionRecordingPlaylistItem.objects.get(playlist=playlist, recording=session_recording_id)

if playlist_item:
playlist_item.delete()
Expand Down
29 changes: 0 additions & 29 deletions mypy-baseline.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion posthog/api/email_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def is_email_verification_disabled(user: User) -> bool:
# using disabled here so that the default state (if no flag exists) is that verification defaults to ON.
return user.organization is not None and posthoganalytics.feature_enabled(
VERIFICATION_DISABLED_FLAG,
user.organization.id,
str(user.organization.id),
groups={"organization": str(user.organization.id)},
group_properties={"organization": {"id": str(user.organization.id)}},
)
Expand Down
17 changes: 9 additions & 8 deletions posthog/api/test/batch_exports/operations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.test.client import Client as TestClient
from rest_framework import status
from posthog.models.utils import UUIDT


def create_batch_export(client: TestClient, team_id: int, batch_export_data: dict | str):
Expand All @@ -16,35 +17,35 @@ def create_batch_export_ok(client: TestClient, team_id: int, batch_export_data:
return response.json()


def pause_batch_export(client: TestClient, team_id: int, batch_export_id: int):
def pause_batch_export(client: TestClient, team_id: int, batch_export_id: UUIDT):
return client.post(f"/api/projects/{team_id}/batch_exports/{batch_export_id}/pause")


def pause_batch_export_ok(client: TestClient, team_id: int, batch_export_id: int):
def pause_batch_export_ok(client: TestClient, team_id: int, batch_export_id: UUIDT):
response = pause_batch_export(client, team_id, batch_export_id)
assert response.status_code == status.HTTP_200_OK, response.json()
return response.json()


def unpause_batch_export(client: TestClient, team_id: int, batch_export_id: int, backfill: bool = False):
def unpause_batch_export(client: TestClient, team_id: int, batch_export_id: UUIDT, backfill: bool = False):
return client.post(
f"/api/projects/{team_id}/batch_exports/{batch_export_id}/unpause",
{"backfill": backfill},
content_type="application/json",
)


def unpause_batch_export_ok(client: TestClient, team_id: int, batch_export_id: int, backfill: bool = False):
def unpause_batch_export_ok(client: TestClient, team_id: int, batch_export_id: UUIDT, backfill: bool = False):
response = unpause_batch_export(client, team_id, batch_export_id, backfill)
assert response.status_code == status.HTTP_200_OK, response.json()
return response.json()


def get_batch_export(client: TestClient, team_id: int, batch_export_id: int):
def get_batch_export(client: TestClient, team_id: int, batch_export_id: UUIDT):
return client.get(f"/api/projects/{team_id}/batch_exports/{batch_export_id}")


def get_batch_export_ok(client: TestClient, team_id: int, batch_export_id: int):
def get_batch_export_ok(client: TestClient, team_id: int, batch_export_id: UUIDT):
response = get_batch_export(client, team_id, batch_export_id)
assert response.status_code == status.HTTP_200_OK, response.json()
return response.json()
Expand All @@ -63,11 +64,11 @@ def get_batch_export_runs_ok(client: TestClient, team_id: int, batch_export_id:
return response.json()


def delete_batch_export(client: TestClient, team_id: int, batch_export_id: int):
def delete_batch_export(client: TestClient, team_id: int, batch_export_id: UUIDT):
return client.delete(f"/api/projects/{team_id}/batch_exports/{batch_export_id}")


def delete_batch_export_ok(client: TestClient, team_id: int, batch_export_id: int):
def delete_batch_export_ok(client: TestClient, team_id: int, batch_export_id: UUIDT):
response = delete_batch_export(client, team_id, batch_export_id)
assert response.status_code == status.HTTP_204_NO_CONTENT, response
return response
Expand Down
2 changes: 1 addition & 1 deletion posthog/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Meta:
class UUIDModel(models.Model):
"""Base Django Model with default autoincremented ID field replaced with UUIDT."""

id = models.UUIDField(primary_key=True, default=UUIDT, editable=False)
id: models.UUIDField = models.UUIDField(primary_key=True, default=UUIDT, editable=False)

class Meta:
abstract = True
Expand Down
7 changes: 4 additions & 3 deletions posthog/plugins/plugin_server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import structlog
from posthog.redis import get_client
from posthog.settings import CDP_FUNCTION_EXECUTOR_API_URL, PLUGINS_RELOAD_PUBSUB_CHANNEL, PLUGINS_RELOAD_REDIS_URL
from posthog.models.utils import UUIDT


logger = structlog.get_logger(__name__)
Expand Down Expand Up @@ -62,7 +63,7 @@ def populate_plugin_capabilities_on_workers(plugin_id: str):

def create_hog_invocation_test(
team_id: int,
hog_function_id: str,
hog_function_id: UUIDT,
globals: dict,
configuration: dict,
mock_async_functions: bool,
Expand All @@ -78,13 +79,13 @@ def create_hog_invocation_test(
)


def get_hog_function_status(team_id: int, hog_function_id: str) -> requests.Response:
def get_hog_function_status(team_id: int, hog_function_id: UUIDT) -> requests.Response:
return requests.get(
CDP_FUNCTION_EXECUTOR_API_URL + f"/api/projects/{team_id}/hog_functions/{hog_function_id}/status"
)


def patch_hog_function_status(team_id: int, hog_function_id: str, state: int) -> requests.Response:
def patch_hog_function_status(team_id: int, hog_function_id: UUIDT, state: int) -> requests.Response:
return requests.patch(
CDP_FUNCTION_EXECUTOR_API_URL + f"/api/projects/{team_id}/hog_functions/{hog_function_id}/status",
json={"state": state},
Expand Down
3 changes: 2 additions & 1 deletion posthog/tasks/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Team,
User,
)
from posthog.models.utils import UUIDT
from posthog.user_permissions import UserPermissions

logger = structlog.get_logger(__name__)
Expand Down Expand Up @@ -159,7 +160,7 @@ def send_fatal_plugin_error(


def send_batch_export_run_failure(
batch_export_run_id: str,
batch_export_run_id: UUIDT,
) -> None:
logger = structlog.get_logger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions posthog/tasks/stop_surveys_reached_target.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from itertools import groupby
from django.db.models import Q
from django.utils import timezone
from uuid import UUID
from datetime import datetime

from posthog.clickhouse.client.connection import Workload
from posthog.client import sync_execute
from posthog.models import Survey
from posthog.models.utils import UUIDT


def _get_surveys_response_counts(
surveys_ids: list[UUID], team_id: int, earliest_survey_creation_date: datetime
surveys_ids: list[UUIDT], team_id: int, earliest_survey_creation_date: datetime
) -> dict[str, int]:
data = sync_execute(
"""
Expand Down
2 changes: 1 addition & 1 deletion posthog/tasks/update_survey_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_targeting_flag(survey: Survey) -> ForeignKey | ForeignKey | Any:
team=survey.team,
created_by=survey.created_by,
active=True,
key=survey.id,
key=str(survey.id),
filters=user_submitted_dismissed_filter,
)
new_flag.save()
Expand Down

0 comments on commit acda90e

Please sign in to comment.