#63 — BUG: allow to recreate tenant.

Repo: Twill-AI/facade State: closed | Status: done Assignee: Unassigned

Created: 2024-08-05 · Updated: 2025-03-24

Description

Steps to reproduce:

  1. Create new tenant under “user@example.com” via POST /self-management/tenant locally or in staging.
  2. Remove this tenant via DELETE
  3. Try to create tenant again.

Expected: there shouldn’t be ability for user to remove tenant in production - see https://github.com/Twill-AI/facade/issues/109. But locally or in staging tenant should have ability to be created again.

Actual: 400 code with body: { "detail": "User(id='b8f5a4b4-c99f-4e0c-946d-f55bb1c495e0', tenant_id='localtenan', scopes=[], name='Owner', disabled=False, created_at=datetime.datetime(2024, 8, 5, 6, 11, 55, 421541, tzinfo=datetime.timezone.utc), email='user@example.com', auth_type=<UserAuthType.EMAIL: 'email'>) already has tenant." }

Explanation:

See https://github.com/Twill-AI/facade/issues/90 for business reasons.

For technical reasons see self_managing_router.remove_tenant - it doesn’t reset DbProfile.tenant_id. But auth.RequiresUserWithoutTenant checks this field to determine “user has tenant already”.

In scope of this bug need to disable DELETE /self-management/tenant if ENVIRONMENT env variable is “production”.

Notes

Add implementation notes, blockers, and context here

Add wikilinks to related people, meetings, or other tickets