Skip to content

fix: make feature flag disable_tenant idempotent to prevent 500 error#140

Open
CCimen wants to merge 1 commit intodevelopfrom
hotfix/templates-feature-flag
Open

fix: make feature flag disable_tenant idempotent to prevent 500 error#140
CCimen wants to merge 1 commit intodevelopfrom
hotfix/templates-feature-flag

Conversation

@CCimen
Copy link
Copy Markdown
Contributor

@CCimen CCimen commented Jan 12, 2026

Changes

  • Changed set.remove() to set.discard() in FeatureFlag.disable_tenant() method
  • Added regression tests for idempotent enable/disable operations

Why

When toggling templates OFF in the admin panel for a tenant that never had templates enabled, the system
returned a 500 Internal Server Error.

Root cause: set.remove(tenant_id) raises KeyError if the tenant_id doesn't exist in the set. Using
set.discard() is the idempotent alternative that safely handles this case.

This affects all users on the latest version who try to toggle templates when they were never enabled, or
toggle off twice in a row.

Testing

  • Added test_disable_tenant_is_idempotent - verifies disabling a never-enabled tenant doesn't crash
  • Added test_enable_tenant_is_idempotent - verifies enabling twice is safe
python -m pytest tests/unittests/feature_flag/test_feature_flag.py -v

Screenshots

N/A - Backend fix only

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant