diff --git a/tests/sentry/api/endpoints/test_debug_files.py b/tests/sentry/api/endpoints/test_debug_files.py index 1349778cdae32f..305ed82f2c6f6e 100644 --- a/tests/sentry/api/endpoints/test_debug_files.py +++ b/tests/sentry/api/endpoints/test_debug_files.py @@ -492,9 +492,7 @@ def test_source_maps_sorting(self): def test_source_maps_delete_archive(self): project = self.create_project(name="foo") - release = Release.objects.create( - organization_id=project.organization_id, version="1", id="1" - ) + release = Release.objects.create(organization_id=project.organization_id, version="1", id=1) release.add_project(project) ReleaseFile.objects.create( diff --git a/tests/sentry/api/endpoints/test_group_notes.py b/tests/sentry/api/endpoints/test_group_notes.py index 58a9ad3057a346..3a3c4dce39efa4 100644 --- a/tests/sentry/api/endpoints/test_group_notes.py +++ b/tests/sentry/api/endpoints/test_group_notes.py @@ -52,6 +52,7 @@ def test_note_merge(self): data={"text": "This looks bad :)"}, datetime=now - datetime.timedelta(days=70), ) + assert note1.data is not None note2 = Activity.objects.create( group=group1, project=project1, @@ -60,6 +61,7 @@ def test_note_merge(self): data={"text": "Yeah we should probably look into this"}, datetime=now - datetime.timedelta(days=66), ) + assert note2.data is not None project2 = self.create_project() group2 = self.create_group(project2) @@ -72,6 +74,7 @@ def test_note_merge(self): data={"text": "I have been a good Sentry :)"}, datetime=now - datetime.timedelta(days=90), ) + assert note3.data is not None note4 = Activity.objects.create( group=group2, project=project2, @@ -80,6 +83,7 @@ def test_note_merge(self): data={"text": "You have been a bad user :)"}, datetime=now - datetime.timedelta(days=88), ) + assert note4.data is not None with self.tasks(): merge_groups([group1.id], group2.id) diff --git a/tests/sentry/api/endpoints/test_project_ownership.py b/tests/sentry/api/endpoints/test_project_ownership.py index 7a0b571de83670..d911b30b217336 100644 --- a/tests/sentry/api/endpoints/test_project_ownership.py +++ b/tests/sentry/api/endpoints/test_project_ownership.py @@ -216,6 +216,7 @@ def test_get(self): # Assert that "identifier" is not renamed to "name" in the backend ownership = ProjectOwnership.objects.get(project=self.project) + assert ownership.schema is not None assert ownership.schema["rules"] == [ { "matcher": {"type": "path", "pattern": "*.js"}, diff --git a/tests/sentry/deletions/test_organization.py b/tests/sentry/deletions/test_organization.py index cfc22a88be046a..28e13330b1382a 100644 --- a/tests/sentry/deletions/test_organization.py +++ b/tests/sentry/deletions/test_organization.py @@ -254,7 +254,7 @@ def test_discover_query_cleanup(self): other = self.create_organization(name="other", owner=self.user) other_project = self.create_project(organization=other, name="other project") - query = DiscoverSavedQuery.objects.create(organization=org, name="test query", query="{}") + query = DiscoverSavedQuery.objects.create(organization=org, name="test query", query={}) # Make a cross-org project reference. This can happen when an account was # merged in the past and we didn't update the discover queries. query_project = DiscoverSavedQueryProject.objects.create( diff --git a/tests/sentry/event_manager/test_event_manager.py b/tests/sentry/event_manager/test_event_manager.py index 78531ab52b18a7..3e5976794b7e4d 100644 --- a/tests/sentry/event_manager/test_event_manager.py +++ b/tests/sentry/event_manager/test_event_manager.py @@ -357,6 +357,7 @@ def test_marks_as_unresolved_with_new_release( assert group.status == GroupStatus.RESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "" assert GroupResolution.objects.filter(group=group).exists() @@ -371,6 +372,7 @@ def test_marks_as_unresolved_with_new_release( assert group.status == GroupStatus.UNRESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "b" assert not GroupResolution.objects.filter(group=group).exists() @@ -431,11 +433,13 @@ def test_that_release_in_latest_activity_prior_to_regression_is_not_overridden( assert group.status == GroupStatus.UNRESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "foobar" regressed_activity = Activity.objects.get( group=group, type=ActivityType.SET_REGRESSION.value ) + assert regressed_activity.data is not None assert regressed_activity.data["version"] == "b" assert regressed_activity.data["follows_semver"] is False @@ -493,12 +497,14 @@ def test_current_release_version_in_latest_activity_prior_to_regression_is_not_o assert group.status == GroupStatus.UNRESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "b" assert activity.data["current_release_version"] == "pre foobar" regressed_activity = Activity.objects.get( group=group, type=ActivityType.SET_REGRESSION.value ) + assert regressed_activity.data is not None assert regressed_activity.data["version"] == "b" mock_send_activity_notifications_delay.assert_called_once_with(regressed_activity.id) @@ -555,11 +561,13 @@ def test_resolved_in_release_regression_activity_follows_semver( assert group.status == GroupStatus.UNRESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "foo@1.0.0" regressed_activity = Activity.objects.get( group=group, type=ActivityType.SET_REGRESSION.value ) + assert regressed_activity.data is not None assert regressed_activity.data["version"] == "foo@2.0.0" assert regressed_activity.data["follows_semver"] is True assert regressed_activity.data["resolved_in_version"] == "foo@1.0.0" @@ -835,6 +843,7 @@ def test_marks_as_unresolved_with_new_release_with_integration( assert group.status == GroupStatus.RESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "" assert GroupResolution.objects.filter(group=group).exists() @@ -853,6 +862,7 @@ def test_marks_as_unresolved_with_new_release_with_integration( assert group.status == GroupStatus.UNRESOLVED activity = Activity.objects.get(id=activity.id) + assert activity.data is not None assert activity.data["version"] == "b" assert not GroupResolution.objects.filter(group=group).exists() diff --git a/tests/sentry/event_manager/test_event_manager_grouping.py b/tests/sentry/event_manager/test_event_manager_grouping.py index e23299ebf14f4f..ccad39cc2470b3 100644 --- a/tests/sentry/event_manager/test_event_manager_grouping.py +++ b/tests/sentry/event_manager/test_event_manager_grouping.py @@ -72,7 +72,7 @@ def test_puts_events_with_only_partial_message_match_in_different_groups(self): def test_adds_default_fingerprint_if_none_in_event(self): event = save_new_event({"message": "Dogs are great!"}, self.project) - assert event.data.get("fingerprint") == ["{{ default }}"] + assert event.data["fingerprint"] == ["{{ default }}"] def test_ignores_fingerprint_on_transaction_event(self): error_event = save_new_event( @@ -116,7 +116,7 @@ def test_updates_group_metadata(self): assert group.times_seen == 1 assert group.last_seen == event1.datetime assert group.message == event1.message - assert group.data.get("metadata").get("title") == event1.title + assert group.data["metadata"]["title"] == event1.title # Normally this should go into a different group, since the messages don't match, but the # fingerprint takes precedence. (We need to make the messages different in order to show @@ -131,7 +131,7 @@ def test_updates_group_metadata(self): assert group.times_seen == 2 assert group.last_seen == event2.datetime assert group.message == event2.message - assert group.data.get("metadata").get("title") == event2.title + assert group.data["metadata"]["title"] == event2.title def test_auto_updates_grouping_config(self): self.project.update_option("sentry:grouping_config", LEGACY_CONFIG) @@ -145,7 +145,7 @@ def test_auto_updates_grouping_config(self): assert self.project.get_option("sentry:grouping_config") == DEFAULT_GROUPING_CONFIG with assume_test_silo_mode_of(AuditLogEntry): - audit_log_entry = AuditLogEntry.objects.first() + audit_log_entry = AuditLogEntry.objects.get() assert audit_log_entry.event == audit_log.get_event_id("PROJECT_EDIT") assert audit_log_entry.actor_label == "Sentry" @@ -237,8 +237,8 @@ def test_fixes_broken_title_data(self): assert group.title == event2.title == "" assert group.data["title"] == event2.data["title"] == "" assert ( - group.data["metadata"].get("title") - == event2.data["metadata"].get("title") + group.data["metadata"]["title"] + == event2.data["metadata"]["title"] == "" ) assert group.message == "" @@ -318,7 +318,7 @@ def test_bug_regression_no_longer_breaks_titles(self): assert event2.data["title"] == "" assert group.data["title"] == "DogsAreNeverAnError: Dogs are great!" assert group.data["metadata"].get("title") is None - assert event2.data["metadata"].get("title") == "" + assert event2.data["metadata"]["title"] == "" assert group.message == "Dogs are great! DogsAreNeverAnError" # An event after the bug was fixed diff --git a/tests/sentry/incidents/action_handlers/test_slack.py b/tests/sentry/incidents/action_handlers/test_slack.py index 4109f36a3436dd..1321ab8cf7e036 100644 --- a/tests/sentry/incidents/action_handlers/test_slack.py +++ b/tests/sentry/incidents/action_handlers/test_slack.py @@ -103,6 +103,7 @@ def test_fire_metric_alert_sdk_error(self, mock_metrics): assert NotificationMessage.objects.all().count() == 1 msg = NotificationMessage.objects.all()[0] assert msg.error_code == 200 + assert msg.error_details is not None assert msg.error_details["data"] == {"ok": False, "error": "invalid_auth"} mock_metrics.incr.assert_called_with( diff --git a/tests/sentry/integrations/msteams/notifications/test_note.py b/tests/sentry/integrations/msteams/notifications/test_note.py index 4a648b04418d53..2fc30f423e6131 100644 --- a/tests/sentry/integrations/msteams/notifications/test_note.py +++ b/tests/sentry/integrations/msteams/notifications/test_note.py @@ -45,6 +45,7 @@ def test_note(self, mock_send_card: MagicMock): f"[{self.group.title}](http://testserver/organizations/{self.organization.slug}/issues/{self.group.id}/?referrer=note\\_activity-msteams&notification\\_uuid=" in body[1]["text"] ) + assert notification.activity.data is not None assert notification.activity.data["text"] == body[2]["text"] notification_uuid = self.get_notification_uuid(body[3]["columns"][1]["items"][0]["text"]) assert ( diff --git a/tests/sentry/integrations/msteams/notifications/test_resolved.py b/tests/sentry/integrations/msteams/notifications/test_resolved.py index 612d036e479823..8b977c5fbecf78 100644 --- a/tests/sentry/integrations/msteams/notifications/test_resolved.py +++ b/tests/sentry/integrations/msteams/notifications/test_resolved.py @@ -82,6 +82,7 @@ def test_resolved_in_release(self, mock_send_card): body = args[1]["body"] assert 4 == len(body) + assert notification.activity.data is not None release_name = notification.activity.data["version"] assert ( f"Issue marked as resolved in {release_name} by {self.user.get_display_name()}" diff --git a/tests/sentry/issues/endpoints/test_organization_group_index.py b/tests/sentry/issues/endpoints/test_organization_group_index.py index 7e2c7131d6a1fc..f3b4f083934617 100644 --- a/tests/sentry/issues/endpoints/test_organization_group_index.py +++ b/tests/sentry/issues/endpoints/test_organization_group_index.py @@ -4112,6 +4112,7 @@ def test_self_assign_issue_next_release(self) -> None: activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" with assume_test_silo_mode(SiloMode.CONTROL): uo1.delete() @@ -4178,7 +4179,7 @@ def test_in_semver_projects_group_resolution_stores_current_release_version(self ident=grp_resolution.id, ) - assert "current_release_version" in activity.data + assert activity.data is not None assert activity.data["current_release_version"] == release_2.version def test_in_non_semver_projects_group_resolution_stores_current_release_version(self) -> None: @@ -4328,6 +4329,7 @@ def test_in_non_semver_projects_resolved_in_next_release_is_equated_to_in_releas type=ActivityType.SET_RESOLVED_IN_RELEASE.value, ident=grp_resolution.id, ) + assert activity.data is not None assert activity.data["version"] == release_2.version def test_selective_status_update(self) -> None: @@ -4397,6 +4399,7 @@ def test_set_resolved_in_current_release(self) -> None: activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == release.version assert GroupHistory.objects.filter( group=group, status=GroupHistoryStatus.SET_RESOLVED_IN_RELEASE @@ -4438,6 +4441,7 @@ def test_set_resolved_in_explicit_release(self) -> None: activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == release.version def test_in_semver_projects_set_resolved_in_explicit_release(self) -> None: @@ -4482,6 +4486,7 @@ def test_in_semver_projects_set_resolved_in_explicit_release(self) -> None: activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == release_1.version assert GroupResolution.has_resolution(group=group, release=release_2) @@ -4519,6 +4524,7 @@ def test_set_resolved_in_next_release(self) -> None: activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" def test_set_resolved_in_next_release_legacy(self) -> None: @@ -4556,6 +4562,7 @@ def test_set_resolved_in_next_release_legacy(self) -> None: activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" def test_set_resolved_in_explicit_commit_unreleased(self) -> None: @@ -4588,6 +4595,7 @@ def test_set_resolved_in_explicit_commit_unreleased(self) -> None: ).exists() activity = Activity.objects.get(group=group, type=ActivityType.SET_RESOLVED_IN_COMMIT.value) + assert activity.data is not None assert activity.data["commit"] == commit.id assert GroupHistory.objects.filter( group=group, status=GroupHistoryStatus.SET_RESOLVED_IN_COMMIT @@ -4626,6 +4634,7 @@ def test_set_resolved_in_explicit_commit_released(self) -> None: ).exists() activity = Activity.objects.get(group=group, type=ActivityType.SET_RESOLVED_IN_COMMIT.value) + assert activity.data is not None assert activity.data["commit"] == commit.id resolution = GroupResolution.objects.get(group=group) @@ -4759,6 +4768,7 @@ def test_snooze_count(self) -> None: assert snooze.user_count is None assert snooze.user_window is None assert snooze.window is None + assert snooze.state is not None assert snooze.state["times_seen"] == 1 assert response.data["status"] == "ignored" @@ -4797,6 +4807,7 @@ def test_snooze_user_count(self) -> None: assert snooze.user_count == 10 assert snooze.user_window is None assert snooze.window is None + assert snooze.state is not None assert snooze.state["users_seen"] == 10 assert response.data["status"] == "ignored" diff --git a/tests/sentry/issues/test_status_change.py b/tests/sentry/issues/test_status_change.py index 2f6ae96b041030..dec4a913646044 100644 --- a/tests/sentry/issues/test_status_change.py +++ b/tests/sentry/issues/test_status_change.py @@ -83,6 +83,7 @@ def test_ignore_new_issue(self, issue_ignored: Any) -> None: assert issue_ignored.called activity = Activity.objects.get(group=self.group, type=ActivityType.SET_IGNORED.value) + assert activity.data is not None assert activity.data.get("ignoreDuration") == 30 assert GroupHistory.objects.filter( @@ -106,6 +107,7 @@ def test_ignore_until_escalating(self, issue_ignored: Any) -> None: assert issue_ignored.called activity = Activity.objects.get(group=self.group, type=ActivityType.SET_IGNORED.value) + assert activity.data is not None assert activity.data.get("ignoreUntilEscalating") assert GroupHistory.objects.filter( diff --git a/tests/sentry/models/test_activity.py b/tests/sentry/models/test_activity.py index 990238edd698ac..aa7c6fe279177a 100644 --- a/tests/sentry/models/test_activity.py +++ b/tests/sentry/models/test_activity.py @@ -49,6 +49,7 @@ def test_get_activities_for_group_priority(self): assert act_for_group[0] == activities[-1] assert act_for_group[1] == activities[-2] assert act_for_group[-1].type == ActivityType.FIRST_SEEN.value + assert act_for_group[-1].data is not None assert act_for_group[-1].data["priority"] == PriorityLevel.HIGH.to_str() def test_get_activities_for_group_simple_priority_ff_on_dups(self): @@ -90,6 +91,7 @@ def test_get_activities_for_group_simple_priority_ff_on_dups(self): assert act_for_group[0] == activities[-1] assert act_for_group[1] == activities[-2] assert act_for_group[-1].type == ActivityType.FIRST_SEEN.value + assert act_for_group[-1].data is not None assert act_for_group[-1].data["priority"] == PriorityLevel.HIGH.to_str() def test_get_activities_for_group_simple(self): diff --git a/tests/sentry/models/test_deploy.py b/tests/sentry/models/test_deploy.py index e7ebdde357bbb4..f1b9c98666b3b2 100644 --- a/tests/sentry/models/test_deploy.py +++ b/tests/sentry/models/test_deploy.py @@ -59,15 +59,11 @@ def test_no_commits_no_head_commits(self): Deploy.notify_if_ready(deploy.id) # make sure activity has been created - assert Activity.objects.filter( + activity = Activity.objects.get( type=ActivityType.DEPLOY.value, project=project, ident=release.version - ).exists() - assert ( - Activity.objects.get( - type=ActivityType.DEPLOY.value, project=project, ident=release.version - ).data["deploy_id"] - == deploy.id ) + assert activity.data is not None + assert activity.data["deploy_id"] == deploy.id assert Deploy.objects.get(id=deploy.id).notified is True def test_head_commits_fetch_not_complete(self): @@ -114,13 +110,9 @@ def test_no_commits_fetch_complete(self): Deploy.notify_if_ready(deploy.id, fetch_complete=True) # make sure activity has been created - assert Activity.objects.filter( + activity = Activity.objects.get( type=ActivityType.DEPLOY.value, project=project, ident=release.version - ).exists() - assert ( - Activity.objects.get( - type=ActivityType.DEPLOY.value, project=project, ident=release.version - ).data["deploy_id"] - == deploy.id ) + assert activity.data is not None + assert activity.data["deploy_id"] == deploy.id assert Deploy.objects.get(id=deploy.id).notified is True diff --git a/tests/sentry/models/test_groupassignee.py b/tests/sentry/models/test_groupassignee.py index e634f27d2d13e5..d07523e54d5000 100644 --- a/tests/sentry/models/test_groupassignee.py +++ b/tests/sentry/models/test_groupassignee.py @@ -41,6 +41,7 @@ def test_assign_user(self): project=self.group.project, group=self.group, type=ActivityType.ASSIGNED.value ) + assert activity.data is not None assert activity.data["assignee"] == str(self.user.id) assert activity.data["assigneeEmail"] == self.user.email assert activity.data["assigneeType"] == "user" @@ -56,6 +57,7 @@ def test_assign_team(self): project=self.group.project, group=self.group, type=ActivityType.ASSIGNED.value ) + assert activity.data is not None assert activity.data["assignee"] == str(self.team.id) assert activity.data["assigneeEmail"] is None assert activity.data["assigneeType"] == "team" @@ -70,6 +72,7 @@ def test_create_only(self): activity = Activity.objects.get( project=self.group.project, group=self.group, type=ActivityType.ASSIGNED.value ) + assert activity.data is not None assert activity.data["assignee"] == str(self.user.id) assert activity.data["assigneeEmail"] == self.user.email assert activity.data["assigneeType"] == "user" @@ -85,6 +88,7 @@ def test_create_only(self): activity = Activity.objects.get( project=self.group.project, group=self.group, type=ActivityType.ASSIGNED.value ) + assert activity.data is not None assert activity.data["assignee"] == str(self.user.id) assert activity.data["assigneeEmail"] == self.user.email assert activity.data["assigneeType"] == "user" @@ -108,10 +112,12 @@ def test_reassign_user_to_team(self): ).order_by("id") ) + assert activity[0].data is not None assert activity[0].data["assignee"] == str(self.user.id) assert activity[0].data["assigneeEmail"] == self.user.email assert activity[0].data["assigneeType"] == "user" + assert activity[1].data is not None assert activity[1].data["assignee"] == str(self.team.id) assert activity[1].data["assigneeEmail"] is None assert activity[1].data["assigneeType"] == "team" @@ -165,6 +171,7 @@ def test_assignee_sync_outbound_assign(self, mock_sync_assignee_outbound): project=self.group.project, group=self.group, type=ActivityType.ASSIGNED.value ) + assert activity.data is not None assert activity.data["assignee"] == str(self.user.id) assert activity.data["assigneeEmail"] == self.user.email assert activity.data["assigneeType"] == "user" diff --git a/tests/sentry/models/test_orgauthtoken.py b/tests/sentry/models/test_orgauthtoken.py index 8012a02ffbd190..cd4ccc8b230cda 100644 --- a/tests/sentry/models/test_orgauthtoken.py +++ b/tests/sentry/models/test_orgauthtoken.py @@ -50,6 +50,7 @@ def test_creates_outboxes(self): assert outbox assert outbox.category == OutboxCategory.ORGAUTHTOKEN_UPDATE_USED assert outbox.object_identifier == token.id + assert outbox.payload is not None assert outbox.payload["organization_id"] == self.organization.id assert outbox.payload["org_auth_token_id"] == token.id assert "date_last_used" in outbox.payload diff --git a/tests/sentry/models/test_outbox.py b/tests/sentry/models/test_outbox.py index 5f3472310dfca8..3adecec2d97c1e 100644 --- a/tests/sentry/models/test_outbox.py +++ b/tests/sentry/models/test_outbox.py @@ -591,7 +591,7 @@ def setUp(self): shard_identifier=shard_id, category=OutboxCategory.WEBHOOK_PROXY, object_identifier=shard_id * 10000 + i, - payload='{"foo": "bar"}', + payload={"foo": "bar"}, ).save() def test_calculate_sharding_depths(self): diff --git a/tests/sentry/tasks/deletion/test_hybrid_cloud.py b/tests/sentry/tasks/deletion/test_hybrid_cloud.py index e638e370c37207..daed20de7f9f2d 100644 --- a/tests/sentry/tasks/deletion/test_hybrid_cloud.py +++ b/tests/sentry/tasks/deletion/test_hybrid_cloud.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from operator import itemgetter +from typing import NotRequired, TypedDict from unittest.mock import patch import pytest @@ -9,9 +12,12 @@ from sentry.db.models import Model, region_silo_model from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey from sentry.discover.models import DiscoverSavedQuery +from sentry.models.group import Group from sentry.models.integrations.external_issue import ExternalIssue from sentry.models.integrations.integration import Integration +from sentry.models.organization import Organization from sentry.models.outbox import ControlOutbox, OutboxScope, outbox_context +from sentry.models.project import Project from sentry.models.savedsearch import SavedSearch from sentry.models.tombstone import RegionTombstone from sentry.models.user import User @@ -293,11 +299,34 @@ def test_set_null_deletion_behavior(task_runner): assert saved_query.created_by_id is None +class _IdParams(TypedDict): + id: NotRequired[int] + + +class _CrossDbDeletionData(TypedDict): + user: User + organization: Organization + project: Project + monitor: Monitor + group: Group + saved_query: DiscoverSavedQuery + + def setup_cross_db_deletion_data( desired_user_id: int | None = None, desired_monitor_id: int | None = None, -): - user = Factories.create_user(id=desired_user_id) +) -> _CrossDbDeletionData: + if desired_user_id is not None: + user_params: _IdParams = {"id": desired_user_id} + else: + user_params = {} + + if desired_monitor_id is not None: + monitor_params = {"id": desired_monitor_id} + else: + monitor_params = {} + + user = Factories.create_user(**user_params) organization = Factories.create_organization(owner=user, name="Delete Me") project = Factories.create_project(organization=organization) group = Factories.create_group(project=project) @@ -308,7 +337,7 @@ def setup_cross_db_deletion_data( created_by_id=user.id, ) monitor = Monitor.objects.create( - id=desired_monitor_id, + **monitor_params, organization_id=organization.id, project_id=project.id, slug="test-monitor", @@ -334,7 +363,7 @@ def setUp(self) -> None: super().setUp() reset_watermarks() - def assert_monitors_unchanged(self, unaffected_data: list[dict]): + def assert_monitors_unchanged(self, unaffected_data: list[_CrossDbDeletionData]) -> None: for u_data in unaffected_data: u_user, u_monitor = itemgetter("user", "monitor")(u_data) queried_monitor = Monitor.objects.get(id=u_monitor.id) @@ -343,12 +372,12 @@ def assert_monitors_unchanged(self, unaffected_data: list[dict]): assert u_monitor.owner_user_id == queried_monitor.owner_user_id assert u_monitor.owner_user_id == u_user.id - def assert_monitors_user_ids_null(self, monitors: list[Monitor]): + def assert_monitors_user_ids_null(self, monitors: list[Monitor]) -> None: for monitor in monitors: monitor.refresh_from_db() assert monitor.owner_user_id is None - def run_hybrid_cloud_fk_jobs(self): + def run_hybrid_cloud_fk_jobs(self) -> None: with override_options({"hybrid_cloud.allow_cross_db_tombstones": True}): with BurstTaskRunner() as burst: schedule_hybrid_cloud_foreign_key_jobs() @@ -514,7 +543,7 @@ def test_get_ids_for_tombstone_cascade_cross_db_watermark_bounds(self): ) ) - bounds_with_expected_results = [ + bounds_with_expected_results_tests = [ ( {"low": 0, "up": in_order_tombstones[1].id}, [cascade_data[0]["monitor"].id, cascade_data[1]["monitor"].id], @@ -541,7 +570,7 @@ def test_get_ids_for_tombstone_cascade_cross_db_watermark_bounds(self): ), ] - for bounds, bounds_with_expected_results in bounds_with_expected_results: + for bounds, bounds_with_expected_results in bounds_with_expected_results_tests: monitor_owner_field = Monitor._meta.get_field("owner_user_id") ids, oldest_obj = get_ids_cross_db_for_tombstone_watermark( @@ -670,7 +699,7 @@ def test_row_watermarking_bounds(self): user = data["user"] User.objects.get(id=user.id).delete() - bounds_with_expected_results = [ + bounds_with_expected_results_tests = [ # Get batch containing first 2 monitors ( {"low": 0, "up": cascade_data[1]["monitor"].id}, @@ -702,7 +731,7 @@ def test_row_watermarking_bounds(self): ), ] - for bounds, bounds_with_expected_results in bounds_with_expected_results: + for bounds, bounds_with_expected_results in bounds_with_expected_results_tests: monitor_owner_field = Monitor._meta.get_field("owner_user_id") ids, oldest_obj = get_ids_cross_db_for_row_watermark( diff --git a/tests/sentry/tasks/test_clear_expired_resolutions.py b/tests/sentry/tasks/test_clear_expired_resolutions.py index f97e3a40d350fa..675bf1a1fc6bc5 100644 --- a/tests/sentry/tasks/test_clear_expired_resolutions.py +++ b/tests/sentry/tasks/test_clear_expired_resolutions.py @@ -71,7 +71,9 @@ def test_simple(self): assert resolution2.status == GroupResolution.Status.pending activity1 = Activity.objects.get(id=activity1.id) + assert activity1.data is not None assert activity1.data["version"] == new_release.version activity2 = Activity.objects.get(id=activity2.id) + assert activity2.data is not None assert activity2.data["version"] == "" diff --git a/tests/sentry/tasks/test_email.py b/tests/sentry/tasks/test_email.py index 8205297356ca45..f4be5bb7068b7e 100644 --- a/tests/sentry/tasks/test_email.py +++ b/tests/sentry/tasks/test_email.py @@ -15,6 +15,7 @@ def test_simple(self): activity = Activity.objects.get(group=group, type=ActivityType.NOTE.value) assert activity.user_id == self.user.id + assert activity.data is not None assert activity.data["text"] == "hello world!" def test_handle_unknown_address(self): diff --git a/tests/sentry/tasks/test_sentry_apps.py b/tests/sentry/tasks/test_sentry_apps.py index 3e6746a3d29f87..bb9544af881957 100644 --- a/tests/sentry/tasks/test_sentry_apps.py +++ b/tests/sentry/tasks/test_sentry_apps.py @@ -467,10 +467,11 @@ def setUp(self): user_id=self.user.id, data={"text": "hello world"}, ) + assert self.note.data is not None self.data = { "comment_id": self.note.id, "timestamp": self.note.datetime, - "comment": self.note.data.get("text"), + "comment": self.note.data["text"], "project_slug": self.note.project.slug, } diff --git a/tests/snuba/api/endpoints/test_group_details.py b/tests/snuba/api/endpoints/test_group_details.py index bfed6d0e73be7a..283c6556e02567 100644 --- a/tests/snuba/api/endpoints/test_group_details.py +++ b/tests/snuba/api/endpoints/test_group_details.py @@ -241,6 +241,7 @@ def test_group_post_priority(self): assert act_for_group[0].type == ActivityType.SET_PRIORITY.value assert act_for_group[-1].type == ActivityType.FIRST_SEEN.value assert act_for_group[0].user_id == self.user.id + assert act_for_group[0].data is not None assert act_for_group[0].data["priority"] == "high" get_response_after = self.client.get(url, format="json") diff --git a/tests/snuba/api/endpoints/test_project_group_index.py b/tests/snuba/api/endpoints/test_project_group_index.py index 4328d4e6dad407..770715759ed2a1 100644 --- a/tests/snuba/api/endpoints/test_project_group_index.py +++ b/tests/snuba/api/endpoints/test_project_group_index.py @@ -607,6 +607,7 @@ def test_self_assign_issue_next_release(self): activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" with assume_test_silo_mode(SiloMode.CONTROL): uo1.delete() @@ -682,6 +683,7 @@ def test_set_resolved_in_current_release(self): activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == release.version def test_set_resolved_in_explicit_release(self): @@ -722,6 +724,7 @@ def test_set_resolved_in_explicit_release(self): activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == release.version def test_set_resolved_in_next_release(self): @@ -760,6 +763,7 @@ def test_set_resolved_in_next_release(self): activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" def test_set_resolved_in_next_release_legacy(self): @@ -793,6 +797,7 @@ def test_set_resolved_in_next_release_legacy(self): activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" @with_feature("organizations:resolve-in-upcoming-release") @@ -832,6 +837,7 @@ def test_set_resolved_in_upcoming_release(self): activity = Activity.objects.get( group=group, type=ActivityType.SET_RESOLVED_IN_RELEASE.value ) + assert activity.data is not None assert activity.data["version"] == "" def test_upcoming_release_flag_validation(self): @@ -906,6 +912,7 @@ def test_set_resolved_in_explicit_commit_unreleased(self): ).exists() activity = Activity.objects.get(group=group, type=ActivityType.SET_RESOLVED_IN_COMMIT.value) + assert activity.data is not None assert activity.data["commit"] == commit.id def test_set_resolved_in_explicit_commit_released(self): @@ -945,6 +952,7 @@ def test_set_resolved_in_explicit_commit_released(self): ).exists() activity = Activity.objects.get(group=group, type=ActivityType.SET_RESOLVED_IN_COMMIT.value) + assert activity.data is not None assert activity.data["commit"] == commit.id resolution = GroupResolution.objects.get(group=group) @@ -1078,6 +1086,7 @@ def test_snooze_count(self): assert snooze.user_count is None assert snooze.user_window is None assert snooze.window is None + assert snooze.state is not None assert snooze.state["times_seen"] == 1 assert response.data["status"] == "ignored" @@ -1119,6 +1128,7 @@ def test_snooze_user_count(self): assert snooze.user_count == 10 assert snooze.user_window is None assert snooze.window is None + assert snooze.state is not None assert snooze.state["users_seen"] == 10 assert response.data["status"] == "ignored"