bug(user): UserDataInitializer blind-INSERTs Administrators group; fails on retry (HIGH, prod-blocking) #518
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
UserDataInitializer.initAdminUserdoes a blindgroupRepository.save(adminGroup)forAdministrators. If a previous boot got partway through the seed (created the group but failed the admin user, OR seeded an admin with a different email that later got cleaned up while leaving the group), the next boot violates the unique constraintuser_groups_name_keyonnameand the application context fails to load.This is exactly the recovery path operators take to fix a misconfigured admin (delete the bad user, restart, expect re-seed). The recovery path is currently a foot-gun.
Code
The same file already uses
findByName(...).orElseGet(...)correctly ininitE2EDatafor the "Leser" group.Reproduction (just observed on staging)
findByEmail(newEmail).isEmpty() == true→ proceeds to seed →groupRepository.save(new UserGroup("Administrators"))→ERROR: duplicate key value violates unique constraint "user_groups_name_key".(In our case the orphan group was on the previous boot's seed — the row had to be manually DELETEd from
user_groups,group_permissions, andapp_users_groupsto unblock.)Impact
Fix
Plus a test in
AdminSeedFailClosedTest(or a new test file) that pins this idempotency: given a pre-existing Administrators group, a fresh admin seed must succeed and use that group, not throw.Discovered
While retrying the staging seed after #513 + #514 + #515 + #517 landed — initial boot had seeded the wrong admin, and the post-fix boot retried into the constraint.