Skip to content

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

Closed
paulvanbrenk wants to merge 4 commits intomainfrom
fix/apn-0d1oa.13-ci
Closed

fix: move EmailTemplate seed to app startup to fix race condition (apn-0d1oa.13)#441
paulvanbrenk wants to merge 4 commits intomainfrom
fix/apn-0d1oa.13-ci

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
  • Removes unnecessary EnsureCreatedAsync call that caused API startup failure in CI

Issue

Closes apn-0d1oa.13

What changed from PR #438

PR #438 included an EnsureCreatedAsync() call that was not in the bug fix spec and caused the API to fail to start in the CI OpenAPI export step. This PR removes that call.

Test plan

  • 425/425 backend tests pass (dotnet test PatchNotes.slnx)
  • Build passes (dotnet build)

🤖 Generated with Claude Code

paulvanbrenk and others added 2 commits February 25, 2026 21:26
…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.
EnsureCreatedAsync at startup prevents the API from starting in CI
environments where the database doesn't exist yet (e.g. OpenAPI spec
export). The SeedDefaultTemplatesAsync method already handles the
empty-table case safely without schema creation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
paulvanbrenk and others added 2 commits February 25, 2026 21:55
…rtup

The startup seed block calls SeedDefaultTemplatesAsync which queries
EmailTemplates. In SQLite environments (dev, test, OpenAPI export CI),
the schema may not exist yet. Gate EnsureCreatedAsync on the SQLite
provider so tests and CI can run without "no such table" errors, while
production SQL Server (which uses migrations) is unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@paulvanbrenk
Copy link
Collaborator Author

Closing — race condition is theoretical; production always has seeded templates.

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