fix: trigger subscription delete not working for non-auto-created credentials (#30122)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Maries 2025-12-24 20:23:52 +08:00 committed by GitHub
parent 02e0fadef7
commit fdaeec7f7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 15 deletions

View File

@ -359,10 +359,6 @@ class TriggerProviderService:
raise ValueError(f"Trigger provider subscription {subscription_id} not found") raise ValueError(f"Trigger provider subscription {subscription_id} not found")
credential_type: CredentialType = CredentialType.of(subscription.credential_type) credential_type: CredentialType = CredentialType.of(subscription.credential_type)
is_auto_created: bool = credential_type in [CredentialType.OAUTH2, CredentialType.API_KEY]
if not is_auto_created:
return None
provider_id = TriggerProviderID(subscription.provider_id) provider_id = TriggerProviderID(subscription.provider_id)
provider_controller: PluginTriggerProviderController = TriggerManager.get_trigger_provider( provider_controller: PluginTriggerProviderController = TriggerManager.get_trigger_provider(
tenant_id=tenant_id, provider_id=provider_id tenant_id=tenant_id, provider_id=provider_id
@ -372,17 +368,20 @@ class TriggerProviderService:
controller=provider_controller, controller=provider_controller,
subscription=subscription, subscription=subscription,
) )
try:
TriggerManager.unsubscribe_trigger( is_auto_created: bool = credential_type in [CredentialType.OAUTH2, CredentialType.API_KEY]
tenant_id=tenant_id, if is_auto_created:
user_id=subscription.user_id, try:
provider_id=provider_id, TriggerManager.unsubscribe_trigger(
subscription=subscription.to_entity(), tenant_id=tenant_id,
credentials=encrypter.decrypt(subscription.credentials), user_id=subscription.user_id,
credential_type=credential_type, provider_id=provider_id,
) subscription=subscription.to_entity(),
except Exception as e: credentials=encrypter.decrypt(subscription.credentials),
logger.exception("Error unsubscribing trigger", exc_info=e) credential_type=credential_type,
)
except Exception as e:
logger.exception("Error unsubscribing trigger", exc_info=e)
session.delete(subscription) session.delete(subscription)
# Clear cache # Clear cache