Error creating team: «new row violates row-level security policy for table "accounts"»
cayblood opened this issue · comments
After generating a boilerplate project and setting up supabase to run locally, I get the following error when trying to create a team for a newly-created user:
If I understand correctly, this new user should be a primary account and therefore should be able to create a team according to the security policies.
I'm also struggling to figure out how to debug postgres issues when running locally. Tailing the logs doesn't really reveal much about why a security policy is failing. Any tips you have here would be greatly appreciated. Thanks!
Just to add detail to this, I'm also getting failing tests, and I'm not sure why:
/tmp/supabase/tests/database/1-basejump-schema-tests.sql .......
# Failed test 5
# (test result was NULL)|Basejump config should have personal accounts enabled
# Failed test 6
# (test result was NULL)|Basejump config should have team accounts enabled
# Failed test 7: "Basejump config should have account billing disabled"
# (test result was NULL)
# Failed test 8: "Basejump config should have stripe as the billing provider"
# (test result was NULL)
# Failed test 9
# (test result was NULL)|Basejump config should have a default trial period
# Failed test 19
# (test result was NULL)|Basejump is_set should be accessible to authenticated users
# Failed test 22: "authenticated users should have access to Basejump config"
# Looks like you failed 7 tests of 22
Failed 7/22 subtests
/tmp/supabase/tests/database/10-account-roles.sql ..............
Dubious, test returned 3 (wstat 768, 0x300)
Failed 17/17 subtests
/tmp/supabase/tests/database/2-personal-accounts.sql ...........
# Failed test 2: "Inserting a user should create a personal account when personal accounts are enabled"
# have: NULL
# want: (1009e39a-fa61-4aab-a762-e7b1f3b014f3,t)
# Failed test 3: "Inserting a user should also add an account_user for the created account"
# have: NULL
# want: (1009e39a-fa61-4aab-a762-e7b1f3b014f3,,owner)
# Failed test 4: "Primary owner should be able to get their own role"
# have: NULL
# want: ("{""account_role"": ""owner"", ""is_primary_owner"": true, ""is_personal_account"": true}")
# Failed test 5: "threw You do not have permission to update this field"
# caught: no exception
# wanted: an exception
# Failed test 6: "Should not be able to delete the primary_owner_user_id from the account_user table"
# have: NULL
# want: (1009e39a-fa61-4aab-a762-e7b1f3b014f3)
# Failed test 9: "threw You do not have permission to update this field"
# caught: no exception
# wanted: an exception
# Failed test 10: "Owner can update their team name"
# Results differ beginning at row 1:
# have: NULL
# want: (test)
# Looks like you failed 7 tests of 15
Failed 7/15 subtests
/tmp/supabase/tests/database/3-personal-accounts-disabled.sql .. ok
/tmp/supabase/tests/database/4-team-accounts.sql ...............
Dubious, test returned 3 (wstat 768, 0x300)
Failed 29/30 subtests
/tmp/supabase/tests/database/5-team-accounts-disabled.sql ...... ok
/tmp/supabase/tests/database/6-invitations.sql .................
Dubious, test returned 3 (wstat 768, 0x300)
Failed 28/28 subtests
/tmp/supabase/tests/database/7-inviting-team-member.sql ........
Dubious, test returned 3 (wstat 768, 0x300)
Failed 8/8 subtests
/tmp/supabase/tests/database/8-inviting-team-owner.sql .........
Dubious, test returned 3 (wstat 768, 0x300)
Failed 9/9 subtests
/tmp/supabase/tests/database/9-profiles.sql ....................
Dubious, test returned 3 (wstat 768, 0x300)
Failed 2/6 subtests
Test Summary Report
-------------------
/tmp/supabase/tests/database/1-basejump-schema-tests.sql (Wstat: 0 Tests: 22 Failed: 7)
Failed tests: 5-9, 19, 22
/tmp/supabase/tests/database/10-account-roles.sql (Wstat: 768 Tests: 0 Failed: 0)
Non-zero exit status: 3
Parse errors: Bad plan. You planned 17 tests but ran 0.
/tmp/supabase/tests/database/2-personal-accounts.sql (Wstat: 0 Tests: 15 Failed: 7)
Failed tests: 2-6, 9-10
/tmp/supabase/tests/database/4-team-accounts.sql (Wstat: 768 Tests: 1 Failed: 0)
Non-zero exit status: 3
Parse errors: Bad plan. You planned 30 tests but ran 1.
/tmp/supabase/tests/database/6-invitations.sql (Wstat: 768 Tests: 0 Failed: 0)
Non-zero exit status: 3
Parse errors: Bad plan. You planned 28 tests but ran 0.
/tmp/supabase/tests/database/7-inviting-team-member.sql (Wstat: 768 Tests: 0 Failed: 0)
Non-zero exit status: 3
Parse errors: Bad plan. You planned 8 tests but ran 0.
/tmp/supabase/tests/database/8-inviting-team-owner.sql (Wstat: 768 Tests: 0 Failed: 0)
Non-zero exit status: 3
Parse errors: Bad plan. You planned 9 tests but ran 0.
/tmp/supabase/tests/database/9-profiles.sql (Wstat: 768 Tests: 4 Failed: 0)
Non-zero exit status: 3
Parse errors: Bad plan. You planned 6 tests but ran 4.
Files=10, Tests=44, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.13 cusr 0.10 csys = 0.26 CPU)
Result: FAIL
Error: error executing command
Try rerunning the command with --debug to troubleshoot the error.
When I first set up the project, all the tests passed. I've since reset the local database but keep getting these issues.
The reset seems to work, although I do get an "Error restoring main".
∴ supabase start
Error restoring main: branch was not dumped.
Applying migration 00000000000001_utility_functions.sql...
Applying migration 00000000000002_accounts.sql...
Applying migration 00000000000003_billing_setup.sql...
Applying migration 00000000000010_profiles.sql...
Applying migration 00000000000011_invitations.sql...
Seeding data supabase/seed.sql...
Started supabase local development setup.
API URL: http://localhost:54321
DB URL: postgresql://postgres:postgres@localhost:54322/postgres
Studio URL: http://localhost:54323
Inbucket URL: http://localhost:54324
JWT secret: super-secret-jwt-token-with-at-least-32-characters-long
anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
service_role key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
I've learned that this error came from deleting supabase/config.toml
and running supabase init
again. Doing that deleted the seed file and caused these errors to occur. After restoring the seed, everything's passing. Sorry for the false alarm!