langgenius/dify · warning · ValueError

Data source is not disabled.

Error message

Data source is not disabled.

What it means

Python ValueError raised at data_source.py:212 in the 'enable' branch of DataSourceApi.patch when the caller sends action=enable but data_source_binding.disabled is already False (binding is already enabled). This is an idempotency/contract violation: enabling an already-enabled binding is rejected. Note this is a bare ValueError (HTTP 500 unless a global handler maps ValueError), not a clean HTTP exception.

Source

Thrown at api/controllers/console/datasets/data_source.py:212

    def patch(
        self, session: Session, current_tenant_id: str, binding_id: UUID, action: Literal["enable", "disable"]
    ) -> tuple[dict[str, str], int]:
        binding_id_str = str(binding_id)
        data_source_binding = session.scalar(
            select(DataSourceOauthBinding).where(
                DataSourceOauthBinding.id == binding_id_str, DataSourceOauthBinding.tenant_id == current_tenant_id
            )
        )
        if data_source_binding is None:
            raise NotFound("Data source binding not found.")
        # enable binding
        match action:
            case "enable":
                if data_source_binding.disabled:
                    data_source_binding.disabled = False
                    data_source_binding.updated_at = naive_utc_now()
                else:
                    raise ValueError("Data source is not disabled.")
            # disable binding
            case "disable":
                if not data_source_binding.disabled:
                    data_source_binding.disabled = True
                    data_source_binding.updated_at = naive_utc_now()
                else:
                    raise ValueError("Data source is disabled.")
        return {"result": "success"}, 200


@console_ns.route("/notion/pre-import/pages")
class DataSourceNotionListApi(Resource):
    @setup_required
    @login_required
    @account_initialization_required
    @console_ns.doc(params=query_params_from_model(DataSourceNotionListQuery))
    @console_ns.response(200, "Success", console_ns.models[NotionIntegrateInfoListResponse.__name__])
    @with_current_user

View on GitHub (pinned to ef8544b173)

Solutions

  1. Refresh the integrations list to see the true disabled state before toggling.
  2. Make the client idempotent: only send 'enable' when the binding is currently disabled.
  3. Guard the endpoint: treat 'enable on enabled' as a no-op success instead of raising ValueError, if backward compatibility allows.
  4. Replace the bare ValueError with a BadRequest/Conflict HTTP exception so the client gets a proper status code.

Example fix

// before (data_source.py:206-212)
case "enable":
    if data_source_binding.disabled:
        data_source_binding.disabled = False
        data_source_binding.updated_at = naive_utc_now()
    else:
        raise ValueError("Data source is not disabled.")
// after — idempotent enable
case "enable":
    if data_source_binding.disabled:
        data_source_binding.disabled = False
        data_source_binding.updated_at = naive_utc_now()
    # already enabled: no-op (still returns success)
Defensive patterns

Strategy: validation

Validate before calling

// Only send 'enable' when the binding is currently disabled.
if (action === 'enable' && binding.disabled === false) {
  // already enabled — skip the call
  return;
}
await patchBinding(binding.id, 'enable');

Type guard

function shouldEnable(b: {disabled: boolean}): boolean { return b.disabled === true; }

Try / catch

try {
  await patchBinding(bindingId, 'enable');
} catch (e) {
  if (/not disabled/i.test(String(e.message||e))) { /* already enabled, ignore */ return; }
  throw e;
}

Prevention

When it happens

Trigger: PATCH /console/api/data-source/integrates/<binding_id>/enable on a binding whose disabled flag is already False. The else-branch of `if data_source_binding.disabled` fires.

Common situations: Double-click on the 'Enable' button; UI state out of sync with server state (shows disabled while server has it enabled); or a retry of a request that already succeeded.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/59dd0bdcee4e0ae1. Report an issue: GitHub.