Repository navigation
fix(api): refuse tenant creation without an extension - #2581
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
Creating a tenant through POST /api/tenants or PUT /api/tenants/:tenant_id without a usable extension crashed with a 500: - With no "extensions" key, TenantController.update/2 reduced over nil and raised Protocol.UndefinedError. - With an empty list, or entries lacking "type" or "settings", Api.create_tenant/1 inserted the tenant and then Migrations.run_migrations/1 raised MatchError in migration_target/1. The tenant row stayed committed with no database settings, so it could never connect or run its migrations. The tenant's database settings live in its extension, so a tenant without one is now refused with a 422 before anything is inserted. The filtering of extension entries is unchanged; it moved into creation_extensions/1, which also checks the result isn't empty. Updates to existing tenants are not affected. Fixes supabase#2580
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Creating a tenant without a usable extension returns a 500. With no
extensionskey,TenantController.update/2raisesProtocol.UndefinedError. With[], or entries missingtypeorsettings, the tenant is inserted first, thenMigrations.run_migrations/1raisesMatchErrorinmigration_target/1. That leaves a committed tenant with no database settings, which can never connect or migrate.What changed
creation_extensions/1inTenantControllerdoes the existing extension filtering and refuses an empty result. The request now gets a 422"extensions must have at least one extension with a type and settings"before anything is inserted.Verification
tenant_controller_test.exstests: POST with noextensions, PUT with[], and PUT with an entry that has nosettings. Each asserts the 422 and that no tenant was created. Onmainthey fail with theProtocol.UndefinedErrorandMatchErrorabove; with the fix they pass.test/realtime_web/controllersandtest/realtime/api_test.exs: 268 tests, 0 failures.mix format --check-formatted,mix compile --force --warnings-as-errorsandmix credoon the changed files pass.Fixes #2580