fix: address 4 defects from CodeRabbit review

- reforge_discovery_ring_async: add non-production guard matching sync version
- is_trial_active/is_trial_expired: check trial_ended flag
- has_primary_s3: include primary_s3_region in validation
- gift card migration downgrade: add missing json_gift_cards drop + existence guards
This commit is contained in:
russell@unturf.com 2026-03-08 00:45:04 -05:00
parent df8f4993c6
commit 92dc61fc50
3 changed files with 32 additions and 6 deletions

View file

@ -305,6 +305,8 @@ class Shop(RBase, Base):
return False
if self.trial_started_timestamp is None:
return False
if self.trial_ended:
return False
import time
now = int(time.time() * 1000)
return now < self.trial_expiry_timestamp
@ -313,6 +315,8 @@ class Shop(RBase, Base):
def is_trial_expired(self):
if self.plan_active or self.trial_started_timestamp is None:
return False
if self.trial_ended:
return True
import time
now = int(time.time() * 1000)
return now >= self.trial_expiry_timestamp
@ -341,6 +345,7 @@ class Shop(RBase, Base):
return bool(
self.primary_s3_enabled
and self.primary_s3_endpoint
and self.primary_s3_region
and self.primary_s3_bucket
and self.primary_s3_access_key
and self.primary_s3_secret_key
@ -884,6 +889,11 @@ def reforge_discovery_ring_async(shop_id, session_factory):
shop = session.get(Shop, shop_id)
if shop is None:
return
if shop.environment is not None and shop.is_non_production:
shop.discovery_ring = []
session.commit()
log.info("Ring cleared for non-production shop %s", shop.name)
return
ring = compute_discovery_ring(shop)
shop.discovery_ring = ring
session.commit()

View file

@ -100,9 +100,17 @@ def upgrade():
def downgrade():
op.drop_table("mps_cart_gift_card")
op.drop_table("mps_gift_card_transaction")
op.drop_table("mps_gift_card")
op.drop_column("mps_shop", "gift_card_enabled")
op.drop_column("mps_shop", "gift_card_min_in_cents")
op.drop_column("mps_shop", "gift_card_max_in_cents")
if _table_exists("mps_cart_gift_card"):
op.drop_table("mps_cart_gift_card")
if _table_exists("mps_gift_card_transaction"):
op.drop_table("mps_gift_card_transaction")
if _table_exists("mps_gift_card"):
op.drop_table("mps_gift_card")
if _column_exists("mps_cart", "json_gift_cards"):
op.drop_column("mps_cart", "json_gift_cards")
if _column_exists("mps_shop", "gift_card_enabled"):
op.drop_column("mps_shop", "gift_card_enabled")
if _column_exists("mps_shop", "gift_card_min_in_cents"):
op.drop_column("mps_shop", "gift_card_min_in_cents")
if _column_exists("mps_shop", "gift_card_max_in_cents"):
op.drop_column("mps_shop", "gift_card_max_in_cents")

View file

@ -2596,6 +2596,8 @@ class TestAsyncDiscoveryRing(unittest.TestCase):
mock_shop = mock.Mock()
mock_shop.products = []
mock_shop.name = "test"
mock_shop.environment = 0
mock_shop.is_non_production = False
# Patch Session and compute to block until we signal
with mock.patch("make_post_sell.models.shop.SASession") as MockSession:
@ -2642,6 +2644,8 @@ class TestAsyncDiscoveryRing(unittest.TestCase):
mock_shop = mock.Mock()
mock_shop.products = []
mock_shop.name = "test"
mock_shop.environment = 0
mock_shop.is_non_production = False
call_count = [0]
@ -2701,6 +2705,8 @@ class TestAsyncDiscoveryRing(unittest.TestCase):
mock_shop = mock.Mock()
mock_shop.products = []
mock_shop.name = "test"
mock_shop.environment = 0
mock_shop.is_non_production = False
call_count = [0]
@ -2758,6 +2764,8 @@ class TestAsyncDiscoveryRing(unittest.TestCase):
mock_shop = mock.Mock()
mock_shop.products = []
mock_shop.name = "test"
mock_shop.environment = 0
mock_shop.is_non_production = False
call_count = [0]