bulk_create_admins returns 500 for new emails or new orgs and leaves partial writes #37
Labels
No labels
bug
chore
data
feature
frontend
good first issue
intermediate
needs/docs
needs/research
needs/upstream
type/bug
type/external
type/feature
type/refactor
urgency
high
urgency
immediate
urgency
low
urgency
medium
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/cal#37
Loading…
Reference in a new issue
No description provided.
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?
What's wrong
The app session is created with
autoflush=False(api/app/services/db.py), andcreate_placeholder_user(),create_organization()andcreate_category()only calldb.add(). So inbulk_create_admins:Admin(user_id=None). The final commit fails with a NOT NULL/primary key error: 500, and nothing is saved. This is the "add a teammate who has never logged in" case in the Manager Dashboard.Category(org_id=None): 500.except Exception(L589-591) never rolls back, so after one failed flush every later email fails too.How to reproduce
As an org1 admin (
bearer(**BOB)with theworldfixture):Returns 500 and no user row is created.
Expected
201: placeholder users and admin rows are created. A failing email is reported in
errorswithout blocking the others, and nothing half-written is committed.Where to look
api/app/api/organizations.pybulk_create_admins()(L494-607).db.begin_nested()so a bad row rolls back alone. Remove the in-loop commit and commit once.2c5f2e9.Done when
api/tests/api/test_bulk_create_admins.py, including one email forced to fail (mockcreate_admin) while the others succeed