Browse Source

chore(hybridcloud) Update django_db to reset all connections (#51552)

Have django manage multiple connections in preparation for the database
split that we'll have in siloed application mode.
Mark Story 1 year ago
parent
commit
7e71ef1d69

+ 1 - 1
tests/sentry/api/endpoints/test_event_ai_suggested_fix.py

@@ -56,7 +56,7 @@ def openai_policy():
         openai_policy_check.disconnect(policy)
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_consent(client, default_project, test_event, openai_policy):
     path = reverse(
         "sentry-api-0-event-ai-fix-suggest",

+ 1 - 1
tests/sentry/api/endpoints/test_event_reprocessable.py

@@ -16,7 +16,7 @@ def auto_login(settings, client, default_user):
     assert client.login(username=default_user.username, password="admin")
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @region_silo_test(stable=True)
 def test_simple(client, factories, default_project):
     min_ago = iso_format(before_now(minutes=1))

+ 4 - 4
tests/sentry/api/endpoints/test_group_hashes_split.py

@@ -38,7 +38,7 @@ def store_stacktrace(default_project, factories):
     return inner
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 def test_basic(client, default_project, store_stacktrace, reset_snuba):
     def _check_merged(seq):
@@ -130,7 +130,7 @@ def test_basic(client, default_project, store_stacktrace, reset_snuba):
     assert _check_merged(2) == group_id
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 def test_split_everything(client, default_project, store_stacktrace, reset_snuba):
     """
@@ -182,7 +182,7 @@ def test_split_everything(client, default_project, store_stacktrace, reset_snuba
     assert event4.group_id not in (event.group_id, event2.group_id, event3.group_id)
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 def test_no_hash_twice(client, default_project, store_stacktrace, reset_snuba):
     """
@@ -211,7 +211,7 @@ def test_no_hash_twice(client, default_project, store_stacktrace, reset_snuba):
     ]
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 def test_materialized_hashes_missing(client, default_project, store_stacktrace, reset_snuba):
     """

+ 7 - 7
tests/sentry/api/endpoints/test_grouping_levels.py

@@ -78,7 +78,7 @@ def _render_all_previews(client):
     return inner
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_error_missing_feature(client, default_project):
     group = Group.objects.create(project=default_project)
 
@@ -88,7 +88,7 @@ def test_error_missing_feature(client, default_project):
         assert response.data["detail"]["code"] == "missing_feature"
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_error_no_events(client, default_project):
     group = Group.objects.create(project=default_project)
 
@@ -98,7 +98,7 @@ def test_error_no_events(client, default_project):
 
 
 @region_silo_test(stable=True)
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 def test_error_not_hierarchical(client, default_project, reset_snuba, factories):
     default_project.update_option("sentry:grouping_config", "mobile:2021-02-12")
@@ -120,7 +120,7 @@ def test_error_not_hierarchical(client, default_project, reset_snuba, factories)
     assert response.data["detail"]["code"] == "issue_not_hierarchical"
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 def test_error_project_not_hierarchical(client, default_organization, reset_snuba, factories):
 
@@ -164,7 +164,7 @@ def _assert_tree_labels(event, functions):
     )
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 @region_silo_test(stable=True)
 def test_downwards(default_project, store_stacktrace, reset_snuba, _render_all_previews):
@@ -215,7 +215,7 @@ b0505d7461a2e36c4a8235bb6c310a3b: ZeroDivisionError | foo | bar2 | baz2 | bam (1
     )
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 @region_silo_test(stable=True)
 def test_upwards(default_project, store_stacktrace, reset_snuba, _render_all_previews):
@@ -280,7 +280,7 @@ level 2*
     )
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.snuba
 @region_silo_test(stable=True)
 def test_default_events(default_project, store_stacktrace, reset_snuba, _render_all_previews):

+ 2 - 2
tests/sentry/api/endpoints/test_project_app_store_connect_credentials.py

@@ -121,7 +121,7 @@ class TestAppStoreConnectRefreshEndpoint:
             },
         )
 
-    @pytest.mark.django_db
+    @pytest.mark.django_db(databases="__all__")
     def test_ok(
         self,
         client,
@@ -140,7 +140,7 @@ class TestAppStoreConnectRefreshEndpoint:
             project_id=default_project.id, config_id=config_id
         )
 
-    @pytest.mark.django_db
+    @pytest.mark.django_db(databases="__all__")
     @override_settings(SENTRY_SELF_HOSTED=False)
     def test_rate_limited(self, client, default_user, mocked_dsym_download_task, refresh_url):
         client.login(username=default_user.username, password="admin")

+ 12 - 12
tests/sentry/api/endpoints/test_relay_projectconfigs.py

@@ -100,7 +100,7 @@ def no_internal_networks(monkeypatch):
     monkeypatch.setattr("sentry.auth.system.INTERNAL_NETWORKS", ())
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_internal_relays_should_receive_minimal_configs_if_they_do_not_explicitly_ask_for_full_config(
     call_endpoint, default_project
 ):
@@ -117,7 +117,7 @@ def test_internal_relays_should_receive_minimal_configs_if_they_do_not_explicitl
     assert safe.get_path(cfg, "config", "groupingConfig") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_internal_relays_should_receive_full_configs(
     call_endpoint, default_project, default_projectkey
 ):
@@ -163,7 +163,7 @@ def test_internal_relays_should_receive_full_configs(
     )
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relays_dyamic_sampling(client, call_endpoint, default_project, dyn_sampling_data):
     """
     Tests that dynamic sampling configuration set in project details are retrieved in relay configs
@@ -181,7 +181,7 @@ def test_relays_dyamic_sampling(client, call_endpoint, default_project, dyn_samp
         assert dynamic_sampling == {"rules": [], "rulesV2": []}
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_trusted_external_relays_should_not_be_able_to_request_full_configs(
     add_org_key, call_endpoint, no_internal_networks
 ):
@@ -189,7 +189,7 @@ def test_trusted_external_relays_should_not_be_able_to_request_full_configs(
     assert status_code == 403
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_when_not_sending_full_config_info_into_a_internal_relay_a_restricted_config_is_returned(
     call_endpoint, default_project
 ):
@@ -202,7 +202,7 @@ def test_when_not_sending_full_config_info_into_a_internal_relay_a_restricted_co
     assert safe.get_path(cfg, "config", "groupingConfig") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_when_not_sending_full_config_info_into_an_external_relay_a_restricted_config_is_returned(
     call_endpoint, add_org_key, relay, default_project
 ):
@@ -218,7 +218,7 @@ def test_when_not_sending_full_config_info_into_an_external_relay_a_restricted_c
     assert safe.get_path(cfg, "config", "groupingConfig") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_trusted_external_relays_should_receive_minimal_configs(
     relay, add_org_key, call_endpoint, default_project, default_projectkey
 ):
@@ -256,7 +256,7 @@ def test_trusted_external_relays_should_receive_minimal_configs(
     assert safe.get_path(cfg, "config", "quotas") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_untrusted_external_relays_should_not_receive_configs(
     call_endpoint, default_project, no_internal_networks
 ):
@@ -277,7 +277,7 @@ def projectconfig_cache_set(monkeypatch):
     return calls
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_projectconfig_cache_minimal_config(
     call_endpoint, default_project, projectconfig_cache_set, task_runner
 ):
@@ -292,7 +292,7 @@ def test_relay_projectconfig_cache_minimal_config(
     assert not projectconfig_cache_set
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_projectconfig_cache_full_config(
     call_endpoint, default_project, projectconfig_cache_set, task_runner
 ):
@@ -317,7 +317,7 @@ def test_relay_projectconfig_cache_full_config(
     assert redis_cfg == http_cfg
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_nonexistent_project(call_endpoint, projectconfig_cache_set, task_runner):
     wrong_id = max(p.id for p in Project.objects.all()) + 1
 
@@ -331,7 +331,7 @@ def test_relay_nonexistent_project(call_endpoint, projectconfig_cache_set, task_
     assert projectconfig_cache_set == [{str(wrong_id): http_cfg}]
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_disabled_project(
     call_endpoint, default_project, projectconfig_cache_set, task_runner
 ):

+ 15 - 15
tests/sentry/api/endpoints/test_relay_projectconfigs_v2.py

@@ -100,7 +100,7 @@ def no_internal_networks(monkeypatch):
     monkeypatch.setattr("sentry.auth.system.INTERNAL_NETWORKS", ())
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_internal_relays_should_receive_minimal_configs_if_they_do_not_explicitly_ask_for_full_config(
     call_endpoint, default_project, default_projectkey
 ):
@@ -117,7 +117,7 @@ def test_internal_relays_should_receive_minimal_configs_if_they_do_not_explicitl
     assert safe.get_path(cfg, "config", "groupingConfig") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_internal_relays_should_receive_full_configs(
     call_endpoint, default_project, default_projectkey
 ):
@@ -164,7 +164,7 @@ def test_internal_relays_should_receive_full_configs(
     )
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relays_dyamic_sampling(
     client, call_endpoint, default_project, default_projectkey, dyn_sampling_data
 ):
@@ -188,7 +188,7 @@ def test_relays_dyamic_sampling(
         assert dynamic_sampling == {"rules": [], "rulesV2": []}
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_trusted_external_relays_should_not_be_able_to_request_full_configs(
     add_org_key, call_endpoint, no_internal_networks
 ):
@@ -196,7 +196,7 @@ def test_trusted_external_relays_should_not_be_able_to_request_full_configs(
     assert status_code == 403
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_when_not_sending_full_config_info_into_a_internal_relay_a_restricted_config_is_returned(
     call_endpoint, default_project, default_projectkey
 ):
@@ -209,7 +209,7 @@ def test_when_not_sending_full_config_info_into_a_internal_relay_a_restricted_co
     assert safe.get_path(cfg, "config", "groupingConfig") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_when_not_sending_full_config_info_into_an_external_relay_a_restricted_config_is_returned(
     call_endpoint, add_org_key, relay, default_project, default_projectkey
 ):
@@ -225,7 +225,7 @@ def test_when_not_sending_full_config_info_into_an_external_relay_a_restricted_c
     assert safe.get_path(cfg, "config", "groupingConfig") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_trusted_external_relays_should_receive_minimal_configs(
     relay, add_org_key, call_endpoint, default_project, default_projectkey
 ):
@@ -263,7 +263,7 @@ def test_trusted_external_relays_should_receive_minimal_configs(
     assert safe.get_path(cfg, "config", "quotas") is None
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_untrusted_external_relays_should_not_receive_configs(
     call_endpoint, default_project, default_projectkey, no_internal_networks
 ):
@@ -283,7 +283,7 @@ def projectconfig_cache_set(monkeypatch):
     return calls
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_projectconfig_cache_minimal_config(
     call_endpoint, default_project, projectconfig_cache_set, task_runner
 ):
@@ -298,7 +298,7 @@ def test_relay_projectconfig_cache_minimal_config(
     assert not projectconfig_cache_set
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_projectconfig_cache_full_config(
     call_endpoint, default_projectkey, projectconfig_cache_set, task_runner
 ):
@@ -323,7 +323,7 @@ def test_relay_projectconfig_cache_full_config(
     assert redis_cfg == http_cfg
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_nonexistent_project(call_endpoint, projectconfig_cache_set, task_runner):
     wrong_public_key = ProjectKey.generate_api_key()
 
@@ -336,7 +336,7 @@ def test_relay_nonexistent_project(call_endpoint, projectconfig_cache_set, task_
     assert projectconfig_cache_set == [{str(wrong_public_key): result["configs"][wrong_public_key]}]
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_disabled_project(
     call_endpoint, default_project, projectconfig_cache_set, task_runner
 ):
@@ -353,7 +353,7 @@ def test_relay_disabled_project(
     assert projectconfig_cache_set == [{str(wrong_public_key): result["configs"][wrong_public_key]}]
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_relay_disabled_key(
     call_endpoint, default_project, projectconfig_cache_set, task_runner, default_projectkey
 ):
@@ -369,7 +369,7 @@ def test_relay_disabled_key(
     assert projectconfig_cache_set == [{str(default_projectkey.public_key): http_cfg}]
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.parametrize("drop_sessions", [False, True])
 def test_session_metrics_extraction(call_endpoint, task_runner, drop_sessions):
     with Feature({"organizations:metrics-extraction": True}), Feature(
@@ -384,7 +384,7 @@ def test_session_metrics_extraction(call_endpoint, task_runner, drop_sessions):
             assert config["sessionMetrics"] == {"version": 1, "drop": drop_sessions}
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.parametrize("abnormal_mechanism_rollout", [0, 1])
 def test_session_metrics_abnormal_mechanism_tag_extraction(
     call_endpoint, task_runner, set_sentry_option, abnormal_mechanism_rollout

+ 6 - 6
tests/sentry/api/endpoints/test_relay_projectconfigs_v3.py

@@ -98,7 +98,7 @@ def project_config_get_mock(monkeypatch):
     )
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_return_full_config_if_in_cache(
     call_endpoint, default_projectkey, projectconfig_cache_get_mock_config
 ):
@@ -110,7 +110,7 @@ def test_return_full_config_if_in_cache(
     }
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_return_partial_config_if_in_cache(
     monkeypatch,
     call_endpoint,
@@ -131,7 +131,7 @@ def test_return_partial_config_if_in_cache(
     assert result == expected
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_proj_in_cache_and_another_pending(
     call_endpoint, default_projectkey, single_mock_proj_cached
 ):
@@ -146,7 +146,7 @@ def test_proj_in_cache_and_another_pending(
 
 
 @patch("sentry.tasks.relay.build_project_config.delay")
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_enqueue_task_if_config_not_cached_not_queued(
     schedule_mock,
     call_endpoint,
@@ -159,7 +159,7 @@ def test_enqueue_task_if_config_not_cached_not_queued(
 
 
 @patch("sentry.tasks.relay.build_project_config.delay")
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_debounce_task_if_proj_config_not_cached_already_enqueued(
     task_mock,
     call_endpoint,
@@ -173,7 +173,7 @@ def test_debounce_task_if_proj_config_not_cached_already_enqueued(
 
 
 @patch("sentry.relay.projectconfig_cache.backend.set_many")
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_task_writes_config_into_cache(
     cache_set_many_mock,
     default_projectkey,

+ 2 - 2
tests/sentry/api/test_authentication.py

@@ -104,7 +104,7 @@ class TestDSNAuthentication(TestCase):
             self.auth.authenticate(request)
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.parametrize("internal", [True, False])
 def test_registered_relay(internal):
     sk, pk = generate_key_pair()
@@ -135,7 +135,7 @@ def test_registered_relay(internal):
     assert request.relay_request_data == data
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 @pytest.mark.parametrize("internal", [True, False])
 def test_statically_configured_relay(settings, internal):
     sk, pk = generate_key_pair()

+ 1 - 1
tests/sentry/dynamic_sampling/rules/biases/test_boost_environments_bias.py

@@ -4,7 +4,7 @@ from sentry.dynamic_sampling import ENVIRONMENT_GLOBS
 from sentry.dynamic_sampling.rules.biases.boost_environments_bias import BoostEnvironmentsBias
 
 
-@pytest.mark.django_db
+@pytest.mark.django_db(databases="__all__")
 def test_generate_bias_rules_v2(default_project):
     rules = BoostEnvironmentsBias().generate_rules(project=default_project, base_sample_rate=0.1)
     assert rules == [

Some files were not shown because too many files changed in this diff