Skip to content

fix: make spec version lookup translatable in test case generation - #34

Merged
admclamb merged 2 commits into
mainfrom
admclamb/fix-testcase-gen-spec-version-query
Oct 17, 2026
Merged

admclamb merged 2 commits into
mainfrom
admclamb/fix-testcase-gen-spec-version-query

Conversation

@admclamb

Copy link
Copy Markdown
Collaborator

Problem

Submitting a problem for validation failed for every setup with:

Test case generation failed for 2 setup(s): Unhandled error: The LINQ expression
'DbSet<TestCaseGenerationSpec>()
    .Where(s => s.ProblemSetupId == __locals1_request_ProblemSetupId)
    .Select(s => s.Version)
    .DefaultIfEmpty(0)' could not be translated.

EF Core can't translate a top-level DefaultIfEmpty over a scalar sequence, so computing the next TestCaseGenerationSpec version threw before any generation work ran. Nothing was wrong with the authored problem content — it hit on every setup, in both JS and Python.

Fix

Aggregate as a nullable int and coalesce in memory. SQL MAX over zero rows returns NULL, which maps to null and becomes 0 — same semantics, fully translatable.

int previousVersion =
    await db
        .Set<TestCaseGenerationSpec>()
        .Where(s => s.ProblemSetupId == request.ProblemSetupId)
        .MaxAsync(s => (int?)s.Version, cancellationToken) ?? 0;

Testing

dotnet build on StackDuel.Infrastructure succeeds (pre-existing CS8603 warnings in GameConfiguration.cs only). Test runs are blocked locally by Application Control, so this leans on CI.

🤖 Generated with Claude Code

admclamb and others added 2 commits October 13, 2026 23:25
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 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@admclamb
admclamb merged commit c31b082 into main Oct 17, 2026
6 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