Skip to content

fix(database): Prevent duplicate primary key on daily stats day rollover#21

Merged
x64-dev merged 1 commit into
mainfrom
seer/fix/daily-stats-day-rollover
Jun 5, 2026
Merged

fix(database): Prevent duplicate primary key on daily stats day rollover#21
x64-dev merged 1 commit into
mainfrom
seer/fix/daily-stats-day-rollover

Conversation

@seer-by-sentry

@seer-by-sentry seer-by-sentry Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the Microsoft.EntityFrameworkCore.DbUpdateException with the inner exception MySqlConnector.MySqlException: Duplicate entry 'PRIMARY' occurring in DailyStatsManager.SaveToDB.

The root cause was identified as the g_StatsContainer static object retaining the previous day's DayOfYear value. When a new calendar day began, SaveToDB would correctly identify that no record existed for the current day, but then attempt to insert g_StatsContainer which still held the previous day's DayOfYear. This led to a primary key violation because a record for the previous day already existed.

The fix involves re-initializing g_StatsContainer with new DailyStat() within the SaveToDB method's entity == null (insert) branch. This ensures that when a new daily stats record is created, g_StatsContainer.DayOfYear is correctly set to the current day, preventing the duplicate key error.

Additionally, the TODO_EFCORE comment regarding preserving old ON DUPLICATE behavior has been removed, as this fix correctly handles the day rollover without needing specific upsert semantics.

Fixes SERVICES-3M

@x64-dev x64-dev merged commit bbd5876 into main Jun 5, 2026
16 checks passed
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