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

chore(deps): Upgrade to Django 4.1 #19285

Merged
merged 4 commits into from
Dec 14, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
---
# name: TestOrganizationResourceAccessAPI.test_list_organization_resource_access_is_not_nplus1.11
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down Expand Up @@ -160,7 +160,7 @@
---
# name: TestOrganizationResourceAccessAPI.test_list_organization_resource_access_is_not_nplus1.3
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/__snapshots__/test_decide.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
---
# name: TestDecide.test_decide_doesnt_error_out_when_database_is_down.3
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_grouptypemapping"
WHERE "posthog_grouptypemapping"."team_id" = 2
LIMIT 1 /*controller='team-detail',route='api/projects/%28%3FP%3Cid%3E%5B%5E/.%5D%2B%29/%3F%24'*/
Expand Down
181 changes: 33 additions & 148 deletions posthog/api/test/__snapshots__/test_feature_flag.ambr

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
---
# name: TestOrganizationFeatureFlagCopy.test_copy_feature_flag_create_new.2
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down Expand Up @@ -1539,7 +1539,7 @@
---
# name: TestOrganizationFeatureFlagCopy.test_copy_feature_flag_create_new.8
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_featureflag"
WHERE (NOT "posthog_featureflag"."deleted"
AND "posthog_featureflag"."key" = 'copied-flag-key'
Expand Down Expand Up @@ -1626,7 +1626,7 @@
---
# name: TestOrganizationFeatureFlagGet.test_get_feature_flag_success.2
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down
8 changes: 4 additions & 4 deletions posthog/api/test/__snapshots__/test_plugin.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
---
# name: TestPluginAPI.test_listing_plugins_is_not_nplus1.15
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down Expand Up @@ -381,7 +381,7 @@
---
# name: TestPluginAPI.test_listing_plugins_is_not_nplus1.21
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down Expand Up @@ -459,7 +459,7 @@
---
# name: TestPluginAPI.test_listing_plugins_is_not_nplus1.3
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down Expand Up @@ -570,7 +570,7 @@
---
# name: TestPluginAPI.test_listing_plugins_is_not_nplus1.9
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_organizationmembership"
WHERE ("posthog_organizationmembership"."organization_id" = '00000000-0000-0000-0000-000000000000'::uuid
AND "posthog_organizationmembership"."user_id" = 2)
Expand Down
9 changes: 9 additions & 0 deletions posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@
OR "posthog_dashboardtile"."insight_id" IS NULL)
AND "posthog_dashboardtile"."dashboard_id" = 2
AND "posthog_dashboardtile"."dashboard_id" = 2
AND NOT ("posthog_dashboard"."deleted"
AND "posthog_dashboardtile"."deleted"
AND "posthog_dashboardtile"."deleted" IS NOT NULL)
AND (NOT "posthog_dashboarditem"."deleted"
OR "posthog_dashboardtile"."insight_id" IS NULL))
ORDER BY "posthog_dashboarditem"."order" ASC /*controller='project_dashboards-detail',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/dashboards/%28%3FP%3Cpk%3E%5B%5E/.%5D%2B%29/%3F%24'*/
Expand Down Expand Up @@ -7351,6 +7354,9 @@
OR "posthog_dashboardtile"."insight_id" IS NULL)
AND "posthog_dashboardtile"."dashboard_id" = 2
AND "posthog_dashboardtile"."dashboard_id" = 2
AND NOT ("posthog_dashboard"."deleted"
AND "posthog_dashboardtile"."deleted"
AND "posthog_dashboardtile"."deleted" IS NOT NULL)
AND (NOT "posthog_dashboarditem"."deleted"
OR "posthog_dashboardtile"."insight_id" IS NULL))
ORDER BY "posthog_dashboarditem"."order" ASC /*controller='project_dashboards-detail',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/dashboards/%28%3FP%3Cpk%3E%5B%5E/.%5D%2B%29/%3F%24'*/
Expand Down Expand Up @@ -10019,6 +10025,9 @@
OR "posthog_dashboardtile"."insight_id" IS NULL)
AND "posthog_dashboardtile"."dashboard_id" = 2
AND "posthog_dashboardtile"."dashboard_id" = 2
AND NOT ("posthog_dashboard"."deleted"
AND "posthog_dashboardtile"."deleted"
AND "posthog_dashboardtile"."deleted" IS NOT NULL)
AND (NOT "posthog_dashboarditem"."deleted"
OR "posthog_dashboardtile"."insight_id" IS NULL))
ORDER BY "posthog_dashboarditem"."order" ASC /*controller='project_dashboards-detail',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/dashboards/%28%3FP%3Cpk%3E%5B%5E/.%5D%2B%29/%3F%24'*/
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ async def acreate_organization(name: str) -> Organization:
could use either the api, or django admin to create, to get better parity
with real world scenarios.
"""
return await sync_to_async(create_organization)(name) # type: ignore
return await sync_to_async(create_organization)(name)
2 changes: 1 addition & 1 deletion posthog/api/test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,4 @@ async def acreate_team(organization: Organization, name: str = "Test team") -> T
could use either the api, or django admin to create, to get better parity
with real world scenarios.
"""
return await sync_to_async(create_team)(organization, name=name) # type: ignore
return await sync_to_async(create_team)(organization, name=name)
2 changes: 1 addition & 1 deletion posthog/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def __init__(self, get_response):
# Some middlewares raise MiddlewareNotUsed if they are not
# needed. In this case we want to avoid the default middlewares
# being used.
middlewares.append(middleware_class(get_response=None))
middlewares.append(middleware_class(get_response=get_response))
except MiddlewareNotUsed:
pass

Expand Down
4 changes: 2 additions & 2 deletions posthog/models/filters/test/__snapshots__/test_filter.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
---
# name: TestDjangoPropertiesToQ.test_person_relative_date_parsing_with_invalid_date
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_person"
INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id")
WHERE ("posthog_persondistinctid"."distinct_id" = 'example_id'
Expand All @@ -359,7 +359,7 @@
---
# name: TestDjangoPropertiesToQ.test_person_relative_date_parsing_with_invalid_date.1
'
SELECT (1) AS "a"
SELECT 1 AS "a"
FROM "posthog_person"
INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id")
WHERE ("posthog_persondistinctid"."distinct_id" = 'example_id'
Expand Down
11 changes: 5 additions & 6 deletions posthog/models/test/test_tagged_item_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.core.exceptions import ValidationError
from django.db import IntegrityError

from posthog.models import Action, Dashboard, DashboardTile, Insight, Tag, TaggedItem
from posthog.test.base import BaseTest
Expand Down Expand Up @@ -28,7 +27,7 @@ def test_uniqueness_constraint_dashboard(self):
tag = Tag.objects.create(name="tag", team_id=self.team.id)

TaggedItem.objects.create(dashboard_id=dashboard.id, tag_id=tag.id)
with self.assertRaises(IntegrityError):
with self.assertRaises(ValidationError):
TaggedItem.objects.create(dashboard_id=dashboard.id, tag_id=tag.id)

def test_uniqueness_constraint_insight(self):
Expand All @@ -38,7 +37,7 @@ def test_uniqueness_constraint_insight(self):
tag = Tag.objects.create(name="tag", team_id=self.team.id)

TaggedItem.objects.create(insight_id=insight.id, tag_id=tag.id)
with self.assertRaises(IntegrityError):
with self.assertRaises(ValidationError):
TaggedItem.objects.create(insight_id=insight.id, tag_id=tag.id)

def test_uniqueness_constraint_event_definition(self):
Expand All @@ -53,7 +52,7 @@ def test_uniqueness_constraint_event_definition(self):
tag = Tag.objects.create(name="tag", team_id=self.team.id)

TaggedItem.objects.create(event_definition_id=event_definition.id, tag_id=tag.id)
with self.assertRaises(IntegrityError):
with self.assertRaises(ValidationError):
TaggedItem.objects.create(event_definition_id=event_definition.id, tag_id=tag.id)

def test_uniqueness_constraint_property_definition(self):
Expand All @@ -68,13 +67,13 @@ def test_uniqueness_constraint_property_definition(self):
tag = Tag.objects.create(name="tag", team_id=self.team.id)

TaggedItem.objects.create(property_definition_id=property_definition.id, tag_id=tag.id)
with self.assertRaises(IntegrityError):
with self.assertRaises(ValidationError):
TaggedItem.objects.create(property_definition_id=property_definition.id, tag_id=tag.id)

def test_uniqueness_constraint_action(self):
action = Action.objects.create(team=self.team, name="enterprise property")
tag = Tag.objects.create(name="tag", team_id=self.team.id)

TaggedItem.objects.create(action_id=action.id, tag_id=tag.id)
with self.assertRaises(IntegrityError):
with self.assertRaises(ValidationError):
TaggedItem.objects.create(action_id=action.id, tag_id=tag.id)
1 change: 1 addition & 0 deletions posthog/settings/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
if get_from_env("DISABLE_SECURE_SSL_REDIRECT", False, type_cast=str_to_bool):
SECURE_SSL_REDIRECT = False

CSRF_TRUSTED_ORIGINS = [os.getenv("SITE_URL", "http://localhost:8000").rstrip("/")]

# Proxy settings
IS_BEHIND_PROXY = get_from_env("IS_BEHIND_PROXY", False, type_cast=str_to_bool)
Expand Down
8 changes: 4 additions & 4 deletions posthog/temporal/batch_exports/batch_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ async def create_export_run(inputs: CreateBatchExportRunInputs) -> str:
# 'sync_to_async' type hints are fixed in asgiref>=3.4.1
# But one of our dependencies is pinned to asgiref==3.3.2.
# Remove these comments once we upgrade.
run = await sync_to_async(create_batch_export_run)( # type: ignore
run = await sync_to_async(create_batch_export_run)(
batch_export_id=uuid.UUID(inputs.batch_export_id),
data_interval_start=inputs.data_interval_start,
data_interval_end=inputs.data_interval_end,
Expand Down Expand Up @@ -542,7 +542,7 @@ async def update_export_run_status(inputs: UpdateBatchExportRunStatusInputs):
run_id=uuid.UUID(inputs.id),
status=inputs.status,
latest_error=inputs.latest_error,
) # type: ignore
)

if batch_export_run.status == "Failed":
logger.error("BatchExport failed with error: %s", batch_export_run.latest_error)
Expand Down Expand Up @@ -583,7 +583,7 @@ async def create_batch_export_backfill_model(inputs: CreateBatchExportBackfillIn
# 'sync_to_async' type hints are fixed in asgiref>=3.4.1
# But one of our dependencies is pinned to asgiref==3.3.2.
# Remove these comments once we upgrade.
run = await sync_to_async(create_batch_export_backfill)( # type: ignore
run = await sync_to_async(create_batch_export_backfill)(
batch_export_id=uuid.UUID(inputs.batch_export_id),
start_at=inputs.start_at,
end_at=inputs.end_at,
Expand All @@ -607,7 +607,7 @@ async def update_batch_export_backfill_model_status(inputs: UpdateBatchExportBac
"""Activity that updates the status of an BatchExportRun."""
backfill = await sync_to_async(update_batch_export_backfill_status)(
backfill_id=uuid.UUID(inputs.id), status=inputs.status
) # type: ignore
)
logger = await bind_temporal_worker_logger(team_id=backfill.team_id)

if backfill.status == "Failed":
Expand Down
16 changes: 8 additions & 8 deletions posthog/temporal/data_imports/external_data_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ class CreateExternalDataJobInputs:

@activity.defn
async def create_external_data_job_model(inputs: CreateExternalDataJobInputs) -> Tuple[str, list[str]]:
run = await sync_to_async(create_external_data_job)( # type: ignore
run = await sync_to_async(create_external_data_job)(
team_id=inputs.team_id,
external_data_source_id=inputs.external_data_source_id,
workflow_id=activity.info().workflow_id,
)

source = await sync_to_async(ExternalDataSource.objects.get)( # type: ignore
source = await sync_to_async(ExternalDataSource.objects.get)(
team_id=inputs.team_id, id=inputs.external_data_source_id
)

# Sync schemas if they have changed
await sync_to_async(sync_old_schemas_with_new_schemas)( # type: ignore
list(PIPELINE_TYPE_SCHEMA_DEFAULT_MAPPING[source.source_type]), # type: ignore
await sync_to_async(sync_old_schemas_with_new_schemas)(
list(PIPELINE_TYPE_SCHEMA_DEFAULT_MAPPING[source.source_type]),
source_id=inputs.external_data_source_id,
team_id=inputs.team_id,
)

schemas = await sync_to_async(get_active_schemas_for_source_id)( # type: ignore
schemas = await sync_to_async(get_active_schemas_for_source_id)(
team_id=inputs.team_id, source_id=inputs.external_data_source_id
)

Expand All @@ -79,7 +79,7 @@ class UpdateExternalDataJobStatusInputs:

@activity.defn
async def update_external_data_job_model(inputs: UpdateExternalDataJobStatusInputs) -> None:
await sync_to_async(update_external_job_status)( # type: ignore
await sync_to_async(update_external_job_status)(
run_id=uuid.UUID(inputs.id),
status=inputs.status,
latest_error=inputs.latest_error,
Expand All @@ -101,7 +101,7 @@ class ValidateSchemaInputs:

@activity.defn
async def validate_schema_activity(inputs: ValidateSchemaInputs) -> None:
await sync_to_async(validate_schema_and_update_table)( # type: ignore
await sync_to_async(validate_schema_and_update_table)(
run_id=inputs.run_id,
team_id=inputs.team_id,
schemas=inputs.schemas,
Expand Down Expand Up @@ -129,7 +129,7 @@ class ExternalDataJobInputs:

@activity.defn
async def run_external_data_job(inputs: ExternalDataJobInputs) -> None:
model: ExternalDataJob = await sync_to_async(get_external_data_job)( # type: ignore
model: ExternalDataJob = await sync_to_async(get_external_data_job)(
team_id=inputs.team_id,
run_id=inputs.run_id,
)
Expand Down
8 changes: 4 additions & 4 deletions posthog/temporal/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ def team(organization):
@pytest_asyncio.fixture
async def aorganization():
name = f"BatchExportsTestOrg-{random.randint(1, 99999)}"
org = await sync_to_async(Organization.objects.create)(name=name) # type: ignore
org = await sync_to_async(Organization.objects.create)(name=name)

yield org

await sync_to_async(org.delete)() # type: ignore
await sync_to_async(org.delete)()


@pytest_asyncio.fixture
async def ateam(aorganization):
name = f"BatchExportsTestTeam-{random.randint(1, 99999)}"
team = await sync_to_async(Team.objects.create)(organization=aorganization, name=name) # type: ignore
team = await sync_to_async(Team.objects.create)(organization=aorganization, name=name)

yield team

await sync_to_async(team.delete)() # type: ignore
await sync_to_async(team.delete)()


@pytest.fixture
Expand Down
Loading
Loading