Skip to content

fix: check account exists before calling BillingService.delete_account#37551

Open
ifer47 wants to merge 1 commit into
langgenius:mainfrom
ifer47:fix/delete-account-check-before-billing
Open

fix: check account exists before calling BillingService.delete_account#37551
ifer47 wants to merge 1 commit into
langgenius:mainfrom
ifer47:fix/delete-account-check-before-billing

Conversation

@ifer47

@ifer47 ifer47 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

In delete_account_task, the account existence check was placed after the billing service deletion call. If the account doesn't exist, BillingService.delete_account() would have already been executed (which may make irreversible external changes) before the task discovers the account is missing and returns early.

Before

account = session.scalar(...)
try:
    if dify_config.BILLING_ENABLED:
        BillingService.delete_account(account_id)  # Runs even if account is None!
except Exception:
    raise

if not account:
    return  # Too late — billing deletion already happened

After

account = session.scalar(...)
if not account:
    return  # Bail out before making any external changes

try:
    if dify_config.BILLING_ENABLED:
        BillingService.delete_account(account_id)
except Exception:
    raise

Test plan

  • Logic is straightforward — the check is simply moved above the billing call
  • Verify that BillingService.delete_account with a non-existent account ID would have caused side effects (the current code path would have hit this in production for any stale Celery task retry)

🤖 Generated with Claude Code Best

The account existence check was placed after the billing service deletion
call. If the account doesn't exist, the billing service would still have
executed its deletion logic (which may be irreversible) before we discover
the account is missing and bail out.

Move the existence check before the billing service call so we return
early without making any external changes when the account is not found.

Co-Authored-By: zhipu/glm-5 <zai-org@claude-code-best.win>
@ifer47 ifer47 requested a review from QuantumGhost as a code owner June 16, 2026 17:58
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 48.59% 48.59% 0.00%
Strict coverage 48.10% 48.10% 0.00%
Typed symbols 27,995 27,995 0
Untyped symbols 29,922 29,922 0
Modules 2892 2892 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant