From 8a7f07b1a9b531a7bb5ca19738bc8a577e633f8f Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:30:32 -0400 Subject: [PATCH] ref: use connection name directly in receivers.core (#72893) more direct, avoids a nullability type error --- src/sentry/receivers/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sentry/receivers/core.py b/src/sentry/receivers/core.py index 69047628c70eba..515c44b03d938b 100644 --- a/src/sentry/receivers/core.py +++ b/src/sentry/receivers/core.py @@ -75,7 +75,8 @@ def create_default_project(id, name, slug, verbosity=2, **kwargs): user = user_service.get_first_superuser() - with transaction.atomic(router.db_for_write(Organization)): + conn_name = router.db_for_write(Organization) + with transaction.atomic(conn_name): with outbox_context(flush=False): org, _ = Organization.objects.get_or_create(slug="sentry", defaults={"name": "Sentry"}) @@ -101,7 +102,7 @@ def create_default_project(id, name, slug, verbosity=2, **kwargs): ) # HACK: Manually update the ID after insert due to Postgres sequence issues. - connection = connections[project._state.db] + connection = connections[conn_name] cursor = connection.cursor() cursor.execute(PROJECT_SEQUENCE_FIX)