From 2cd6ea694f2d4249978c1e013d4667dd2bb606dd Mon Sep 17 00:00:00 2001 From: admclamb Date: Tue, 13 Oct 2026 23:25:41 -0400 Subject: [PATCH] fix: make spec version lookup translatable in test case generation EF Core cannot translate a top-level DefaultIfEmpty over a scalar sequence, so computing the next TestCaseGenerationSpec version threw before any generation ran and every validation submission failed. Aggregate as a nullable int and coalesce in memory instead: SQL MAX over zero rows yields NULL, which maps to null and becomes 0. Co-Authored-By: Claude Opus 5 --- .../TestCaseGeneration/TestCaseGenerationService.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/StackDuel.Infrastructure/TestCaseGeneration/TestCaseGenerationService.cs b/StackDuel.Infrastructure/TestCaseGeneration/TestCaseGenerationService.cs index 9828283..d5f1158 100644 --- a/StackDuel.Infrastructure/TestCaseGeneration/TestCaseGenerationService.cs +++ b/StackDuel.Infrastructure/TestCaseGeneration/TestCaseGenerationService.cs @@ -87,12 +87,11 @@ public async Task GenerateAsync( // only looks at whether a spec is attached, not whether generation actually finished. await using var transaction = await db.Database.BeginTransactionAsync(cancellationToken); - int previousVersion = await db - .Set() - .Where(s => s.ProblemSetupId == request.ProblemSetupId) - .Select(s => s.Version) - .DefaultIfEmpty(0) - .MaxAsync(cancellationToken); + int previousVersion = + await db + .Set() + .Where(s => s.ProblemSetupId == request.ProblemSetupId) + .MaxAsync(s => (int?)s.Version, cancellationToken) ?? 0; var spec = new TestCaseGenerationSpec( request.ProblemSetupId,