diff --git a/apps/accounts/serializers/account/template.py b/apps/accounts/serializers/account/template.py index d2d992ea6..ffe8c7564 100644 --- a/apps/accounts/serializers/account/template.py +++ b/apps/accounts/serializers/account/template.py @@ -23,8 +23,12 @@ class AccountTemplateSerializer(BaseAccountSerializer): def sync_accounts_secret(self, instance, diff): if not self._is_sync_account or 'secret' not in diff: return - - accounts = Account.objects.filter(source_id=instance.id) + query_data = { + 'source_id': instance.id, + 'username': instance.username, + 'secret_type': instance.secret_type + } + accounts = Account.objects.filter(**query_data) instance.bulk_sync_account_secret(accounts, self.context['request'].user.id) def validate(self, attrs): @@ -38,7 +42,10 @@ class AccountTemplateSerializer(BaseAccountSerializer): if getattr(instance, k, None) != v } instance = super().update(instance, validated_data) - self.sync_accounts_secret(instance, diff) + if {'username', 'secret_type'} & set(diff.keys()): + Account.objects.filter(source_id=instance.id).update(source_id=None) + else: + self.sync_accounts_secret(instance, diff) return instance