fix #1355: retrieve DbSet to List before iteration to to prevent npgsql crash#1356
Merged
Conversation
…vent `NpgsqlOperationInProgressException` on PostgreSQL. Iterating directly over DbSet inside a loop that issues further queries on the same context fails on PostgreSQL (no MARS support). Fixed by calling ToList() before the affected foreach loops in SeedOwnedSkillsForPeople, SeedCompetencyAssessments, and SeedTimesheets.
Contributor
Author
|
I would suggest renaming the Check Repository Ruleset / check-ruleset (pull_request) check. It implies a code failing, however, to my understanding it is just complaining because no-one has reviewed the PR yet. Naming the actions pipeline stage something like "PR is reviewed by a CoP member" could help? |
Contributor
Author
|
Pause on this until I can add the fix from #1355 (comment) please! |
Contributor
Author
|
^ that's the fix for that, but I'm going to review the rest of the codebase for this pattern too. |
Contributor
Author
|
Done. This PR is ready for review! |
npgsql crash
npgsql crashDbSet to List before iteration to to prevent npgsql crash
aharwood2
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1355.
Iterating directly over a
DbSetwhile issuing further queries on the sameDbContextinside the loop fails on PostgreSQL.Npgsql rejects the second command because a reader is already open on the connection. SQLite silently tolerates this; SQL Server likely just requires
MultipleActiveResultSets=Truein the connection string to avoid the same issue.The behaviour was initially visible in the database seeding routines, but the pattern also exists elsewhere.
Fixed by retrieving the outer collections into lists with
.ToList()before entering the affected loops inSeedOwnedSkillsForPeople,SeedCompetencyAssessments, andSeedTimesheets. No behaviour change on any provider: just fixes thenpgsqlcrash.I've also included fixes for
TimesheetServiceandGetSkillsForProject, which use the same pattern.Tested by running:
SEED_DUMMY_DATA=TRUE DB_PROVIDER=sqlite dotnet run: seeding completes without error (no regression)SEED_DUMMY_DATA=TRUE DB_PROVIDER=postgresql dotnet run: seeding completes without error