From f37eb9a1bd6a149f38458b1a4a1071efd8c03660 Mon Sep 17 00:00:00 2001 From: Fringg Date: Wed, 29 Apr 2026 08:04:23 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20cabinet=20purchase=20fails=20after=20pan?= =?UTF-8?q?el=20user=20deletion=20=E2=80=94=20stale=20UUID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs caused "RemnaWave UUID не найден" when a user repurchased after their panel user was deleted (expired user cleanup): 1. Webhook handler only cleared subscription.remnawave_uuid in multi-tariff mode. In single-tariff mode the stale UUID remained, causing the cabinet to try update_remnawave_user on a deleted panel user instead of creating a new one. 2. Cabinet purchase-tariff used subscription.remnawave_uuid for the create/update decision. In single-tariff mode this was stale. Now mirrors the bot handler logic: checks user.remnawave_uuid in single-tariff mode (correctly cleared by webhook). --- app/cabinet/routes/subscription_modules/purchase.py | 11 ++++++++--- app/services/remnawave_webhook_service.py | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/cabinet/routes/subscription_modules/purchase.py b/app/cabinet/routes/subscription_modules/purchase.py index 1c56429d..d122af1c 100644 --- a/app/cabinet/routes/subscription_modules/purchase.py +++ b/app/cabinet/routes/subscription_modules/purchase.py @@ -895,8 +895,14 @@ async def purchase_tariff( except Exception as trial_err: logger.warning('Failed to disable trial on RemnaWave', error=trial_err, trial_id=trial_sub.id) try: - if subscription.remnawave_uuid: - # Existing subscription with Remnawave user — update it + # Mirror the bot handler logic: in single-tariff mode, check user.remnawave_uuid + # (webhook clears it on panel deletion), not subscription.remnawave_uuid + if settings.is_multi_tariff_enabled(): + _should_create = not subscription.remnawave_uuid + else: + _should_create = not getattr(user, 'remnawave_uuid', None) + + if not _should_create: await service.update_remnawave_user( db, subscription, @@ -905,7 +911,6 @@ async def purchase_tariff( sync_squads=True, ) else: - # New subscription — create new Remnawave user await service.create_remnawave_user( db, subscription, diff --git a/app/services/remnawave_webhook_service.py b/app/services/remnawave_webhook_service.py index b3d62835..9f9530b6 100644 --- a/app/services/remnawave_webhook_service.py +++ b/app/services/remnawave_webhook_service.py @@ -1075,8 +1075,8 @@ class RemnaWaveWebhookService: subscription.connected_squads = [] subscription.updated_at = datetime.now(UTC) - if settings.is_multi_tariff_enabled(): - subscription.remnawave_uuid = None + # Always clear stale UUID — panel user was deleted + subscription.remnawave_uuid = None await db.execute(delete(SubscriptionServer).where(SubscriptionServer.subscription_id == sub_id))