seed_demo: a refused run still marks the account's address verified and primary, never clearing the old primary #496
Labels
No labels
accessibility
authentication
breaking change
bug
documentation
enhancement
interface
internationalisation
observability
performance
security
tier
1
tier
2
tier
3
tier/4
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo#496
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?
Found on 2026-09-29 in a read-only review of postulo at
95348908d, readingseed_demo'shandle.Checked again on 2026-10-01 against
mainat0a5cad587: still present.seed_demorefuses to add to an account that already holds a search, but only after it has already written to that account's addresses. It sets the address matchinguser.emailto verified and primary before the check, outside the transaction that guards the seeding. It also never clears any other primary address. A run that reports an error has therefore still changed the account.Command.handleincore/management/commands/seed_demo.py:293-318. TheEmailAddress.objects.update_or_create(..., defaults={"email": user.email, "verified": True, "primary": True})is at:304-308. Thehas_datacheck andraise CommandError(...)come after it, at:310-318, andtransaction.atomic()starts at:320.seed_demowith the address of an existing account that holds a search, perhaps their own, as Getting started and the README suggest withseed_demo you@example.org. The command answers "That account already holds a job search" and exits with an error. That account'sEmailAddressrow foruser.emailis nowverified=True, primary=Trueanyway. For an account whose people have signed in, this is normally the row that was already primary and verified, so nothing visible changes. It does change something whenuser.emailno longer matches the primaryEmailAddress, which happens when an account's address is edited through the Django admin (accounts/admin.py:21, mounted whenPOSTULO_ADMIN_URLis set): a second row is created, or updated, as primary, and the account then has two primary addresses.allauthand Postulo's own code (plugins/email/__init__.py:45orders by-primary) disagree about which address is the account's. That affects where mail is sent and which address shows as the account's own. The operator vouching for an address at the console is deliberate, as increate_superuser(accounts/models.py:85-95), and is not the defect here.has_datacheck and itsCommandErrorabove every write. Vouch for the address inside thetransaction.atomic()block, after the check, and do it with allauth'sEmailAddress.set_as_primary()(or clearprimaryon the user's other rows first), so the account keeps exactly one primary address.create_superuserhas the sameupdate_or_createwithout clearing other primaries, which is harmless there because the account is new. A shared helper inaccountswould keep the two from drifting apart.Done when
tests/test_seed_demo.py: runningseed_demoagainst an account that holds a search, and whose onlyEmailAddressis unverified, raisesCommandErrorand leaves that row unverified. Running it on an account whoseuser.emaildiffers from its primaryEmailAddressleaves exactly one primary row. Both fail today.