From 25e1d6947c09d55a9165e13e5d2911023aaae39c Mon Sep 17 00:00:00 2001 From: Buck Evan Date: Wed, 11 Oct 2023 15:04:01 -0500 Subject: [PATCH] code review: is only None tested? --- src/sentry/models/outbox.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/sentry/models/outbox.py b/src/sentry/models/outbox.py index f5fc74d1027bf5..f87d981c415c21 100644 --- a/src/sentry/models/outbox.py +++ b/src/sentry/models/outbox.py @@ -529,7 +529,7 @@ def lock_id(self, attrs: Iterable[str]) -> int: def process_shard( self, latest_shard_row: OutboxBase | None ) -> Generator[OutboxBase | None, None, None]: - flush_all: bool = not bool(latest_shard_row) + latest_shard_row = None using: str = db.router.db_for_write(type(self)) shard_lock_id = self.lock_id(self.sharding_columns) @@ -537,12 +537,9 @@ def process_shard( try: with connections[using].cursor() as cursor: - if flush_all: - cursor.execute("SELECT pg_try_advisory_lock(%s)", [shard_lock_id]) - if not cursor.fetchone()[0]: - obtained_lock = False - else: - cursor.execute("SELECT pg_advisory_lock(%s)", [shard_lock_id]) + cursor.execute("SELECT pg_try_advisory_lock(%s)", [shard_lock_id]) + if not cursor.fetchone()[0]: + obtained_lock = False if obtained_lock: next_shard_row: OutboxBase | None