Skip to content

fix: move EmailTemplate seed to app startup to fix race condition (apn-0d1oa.13)#438

Closed
paulvanbrenk wants to merge 1 commit intomainfrom
merge/apn-0d1oa.13
Closed

fix: move EmailTemplate seed to app startup to fix race condition (apn-0d1oa.13)#438
paulvanbrenk wants to merge 1 commit intomainfrom
merge/apn-0d1oa.13

Conversation

@paulvanbrenk
Copy link
Collaborator

Summary

  • Fixes P1 bug: EmailTemplate seed-on-first-access had a race condition under concurrent requests
  • Moves seeding to app startup to ensure it runs once before any requests are served

Issue

Closes apn-0d1oa.13

Test plan

  • 425/425 tests pass (dotnet test PatchNotes.slnx)

🤖 Merged by Refinery (ai_patch_notes merge queue processor)

…n-0d1oa.13)

Two concurrent GETs could both see empty EmailTemplates table, both call
SeedDefaultTemplatesAsync, and the second SaveChangesAsync would throw a
unique constraint violation on the template Name column.

Fix: seed at app startup using a scoped service before the app handles
any requests. EnsureCreatedAsync is called first so startup works in
test environments that use in-memory SQLite without migrations.
@paulvanbrenk
Copy link
Collaborator Author

Closing in favor of #441 which fixes the EnsureCreatedAsync startup issue.

auto-merge was automatically disabled February 26, 2026 02:50

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant