[PR #11993] fix: --name option for the create-tenant command does not take effect #27448

Closed
opened 2026-02-21 20:41:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/11993

State: closed
Merged: Yes


Summary

Fixes #11991

The issue is:

When run create_tenant command, it first registers an account, and then call create_owner_tenant_if_not_exist method. (api/commands.py:565

However, a default tenant will be created during the register account process.

    # api/services/account_service.py:815
    def register(
        ...
    ) -> Account:
        create account...

            if FeatureService.get_system_features().is_allow_create_workspace:
                tenant = TenantService.create_tenant(f"{account.name}'s Workspace")

Therefore, a tenant will always exist when create_owner_tenant_if_not_exist is called, and won't create a tenant with --name option.

    # api/services/account_service.py:517
    # available_ta will always be true
    def create_owner_tenant_if_not_exist(
        account: Account, name: Optional[str] = None, is_setup: Optional[bool] = False
    ):
        """Check if user have a workspace or not"""
        available_ta = (
            TenantAccountJoin.query.filter_by(account_id=account.id).order_by(TenantAccountJoin.id.asc()).first()
        )

        if available_ta:
            return

Screenshots

Run command:

cd api
poetry run python -m flask create-tenant --email 'admin@local.com' --name "Custom Tenant" --language 'zh-Hans'
Before After
image image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/11993 **State:** closed **Merged:** Yes --- # Summary Fixes #11991 The issue is: When run `create_tenant` command, it first registers an account, and then call `create_owner_tenant_if_not_exist` method. (`api/commands.py:565`) However, a default tenant will be created during the register account process. ```py # api/services/account_service.py:815 def register( ... ) -> Account: create account... if FeatureService.get_system_features().is_allow_create_workspace: tenant = TenantService.create_tenant(f"{account.name}'s Workspace") ``` Therefore, a tenant will always exist when `create_owner_tenant_if_not_exist` is called, and won't create a tenant with --name option. ```py # api/services/account_service.py:517 # available_ta will always be true def create_owner_tenant_if_not_exist( account: Account, name: Optional[str] = None, is_setup: Optional[bool] = False ): """Check if user have a workspace or not""" available_ta = ( TenantAccountJoin.query.filter_by(account_id=account.id).order_by(TenantAccountJoin.id.asc()).first() ) if available_ta: return ``` # Screenshots Run command: ```sh cd api poetry run python -m flask create-tenant --email 'admin@local.com' --name "Custom Tenant" --language 'zh-Hans' ``` | Before | After | |--------|-------| |<img width="718" alt="image" src="https://github.com/user-attachments/assets/2e1ca509-f63b-4fcf-bb37-a61a17536170" />|<img width="715" alt="image" src="https://github.com/user-attachments/assets/10e4c3db-e990-4c7d-939c-aa7b031ff201" />| # Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:41:32 -05:00
yindo closed this issue 2026-02-21 20:41:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#27448