You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: add ValueComparer for AdminUsersView.Roles - #404
Adds an explicit ValueComparer<List<RoleType>> to the AdminUsersView.Roles value converter in Common/OpenShockDb/OpenShockContext.cs, along with a brief inline comment explaining why .HasConversion(x => x.ToArray(), x => x.ToList()) must be kept.
Removing the converter breaks GET /1/admin/users (GetUsers.cs) with an InvalidCastException (RoleType[] to List<RoleType>) because Z.EntityFramework.Plus.Future() wraps the reader in CreateEntityDataReader, which calls NpgsqlDataReader.GetValue() (returning RoleType[]) and casts directly to T—the same issue noted in EmailOutboxList.cs. Keeping the converter with a ValueComparer silences CoreEventId.CollectionWithoutComparer without breaking .Future() batching or changing the database schema/snapshot.
How was it tested?
Verified no pending EF Core model changes with dotnet ef migrations has-pending-model-changes --project Common --startup-project MigrationHelper --context MigrationOpenShockContext.
Added unit tests in Common.Tests/OpenShockDb/OpenShockContextModelTests.cs confirming OpenShockContext initializes without emitting CoreEventId.CollectionWithoutComparer and that AdminUsersView.Roles has both a ValueConverter and ValueComparer.
Added integration tests in API.IntegrationTests/Tests/AdminUsersViewTests.cs, including HTTP tests against GET /1/admin/users exercising Z.EntityFramework.Plus.Future() / .FutureValue() and DynamicLinq for both empty and populated Roles.
Built in Debug and Release (0 warnings/errors) and ran the full Release test suite (dotnet test -c Release --solution OpenShockBackend.slnx): all 454 tests passed.
Checklist
The change is focused on one thing.
Tests, formatter and linter pass locally.
Documentation is updated where behaviour changed.
No secrets, credentials or personal data are included.
If this touches device control, limits, sharing, authentication or firmware updates, the description says so and explains how it was tested.
No actionable comments were generated in the recent review.
Walkthrough
The AdminUsersView.Roles mapping retains its value converter and adds a value comparer. Model tests check the comparer and its snapshots. Integration tests cover role materialization and admin endpoint filtering, ordering, and pagination.
Changes: Admin role array mapping
Layer / File(s)
Summary
Role array mapping and comparer checks Common/OpenShockDb/OpenShockContext.cs, Common.Tests/OpenShockDb/OpenShockContextModelTests.cs
The mapping retains the List<RoleType> to RoleType[] conversion and adds a comparer for list equality, hashing, and snapshots. The model test checks the converter, comparer, column type, warning logs, equality, and snapshots.
Role materialization tests API.IntegrationTests/Tests/AdminUsersViewTests.cs
Integration tests check empty and populated role lists. Endpoint tests check filtered, sorted, paginated results and an unfiltered response.
This change adds a value comparer to the admin users view role mapping to silence a repeated EF Core warning. It is a read-only view, so no migration is needed. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the change: a ValueComparer is added for AdminUsersView.Roles. The raw summary and the commit message both confirm that OpenShockContext now supplies a ValueComparer for List…
Linked Issues check
[#336] asks to stop the EF Core CollectionWithoutComparer warning on AdminUsersView.Roles. It prefers removing the converter. It allows adding a proper ValueComparer<List> if the converter m…
Out of Scope Changes check
The whole-PR diff against merge base 2adf062 changes one mapping in Common/OpenShockDb/OpenShockContext.cs. It adds the EF Core ChangeTracking using and a ValueComparer for AdminUsersView.Roles. This…
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the change: a ValueComparer is added for AdminUsersView.Roles. The raw summary and the commit message both confirm that OpenShockContext now supplies a ValueComparer for List<RoleType>. The PR description says the converter should be removed instead, but the commit message and the code summary show the ValueComparer approach was implemented. The issue allows this option, so the title matches the changeset. The 'fix:' prefix fits the warning-silencing purpose.
Full details: Linked Issues check
Explanation
[#336] asks to stop the EF Core CollectionWithoutComparer warning on AdminUsersView.Roles. It prefers removing the converter. It allows adding a proper ValueComparer<List<RoleType>> if the converter must stay. The reviewed head keeps HasConversion(x => x.ToArray(), x => x.ToList()) and adds a ValueComparer<List<RoleType>> with equality (SequenceEqual), hash, and snapshot (ToList) delegates in Common/OpenShockDb/OpenShockContext.cs. This is the permitted alternative. The model test ModelInitialization_DoesNotLogCollectionWithoutComparerWarning in Common.Tests/OpenShockDb/OpenShockContextModelTests.cs asserts a comparer exists, the column type is role_type[], no CollectionWithoutComparer log is emitted, and the comparer equality and snapshot behave correctly. The code comment states that removing the converter breaks AdminController.GetUsers through the Z.EntityFramework.Plus Future path (InvalidCastException). The integration tests in API.IntegrationTests/Tests/AdminUsersViewTests.cs cover materialization for empty and populated role lists, as #336 requests. Limits: the PR description still says the converter is removed, and the claimed Z.EntityFramework.Plus cause was not verified in source. I did not run the tests. The PASS rests on the code diff and the test content.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against merge base 2adf062 changes one mapping in Common/OpenShockDb/OpenShockContext.cs. It adds the EF Core ChangeTracking using and a ValueComparer for AdminUsersView.Roles. This implements #336. The test changes in Common.Tests/OpenShockDb/OpenShockContextModelTests.cs and API.IntegrationTests/Tests/AdminUsersViewTests.cs verify this mapping. The integration test summary also covers filtering, ordering, offset, and limit on the admin users endpoint. These checks test the same view that the change affects, so they are closely related to the mapping. No unrelated change was found. The PR description is out of date. It describes converter removal, but the code keeps the converter. This is a documentation mismatch, not an out-of-scope change.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MeowLuckly
changed the title
fix: remove redundant value converter on AdminUsersView.Roles
fix: add ValueComparer for AdminUsersView.Roles
Nov 27, 2026
Good catch — you were right! I dug into GetUsers.cs and found the exact reason removing .HasConversion(...) breaks:
GET /1/admin/users uses Z.EntityFramework.Plus (.Future() / .FutureValue()), whose CreateEntityDataReader.GetFieldValue<T>() calls NpgsqlDataReader.GetValue() (which returns RoleType[] for role_type[]) and casts directly to T. Without the RoleType[] value converter, EF Core requests GetFieldValue<List<RoleType>>() and throws an InvalidCastException — the same CreateEntityDataReader limitation noted in EmailOutboxList.cs.
I've updated the PR to:
Keep .HasConversion(x => x.ToArray(), x => x.ToList()) and attach an explicit ValueComparer<List<RoleType>> (with a short comment explaining why the converter is needed for .Future()).
Add HTTP integration tests for GET /1/admin/users covering the full .Future() + DynamicLinq path for empty and populated Roles.
Update the unit test to verify both the converter and comparer are present and CoreEventId.CollectionWithoutComparer is no longer emitted.
All 454 tests pass locally (and no pending EF model changes). Ready for another look!
At this point idk what the value of this pr is anymore 🤔
This branch has not been deployed
No deployments
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
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.
What does this change?
Closes #336
Adds an explicit
ValueComparer<List<RoleType>>to theAdminUsersView.Rolesvalue converter inCommon/OpenShockDb/OpenShockContext.cs, along with a brief inline comment explaining why.HasConversion(x => x.ToArray(), x => x.ToList())must be kept.Removing the converter breaks
GET /1/admin/users(GetUsers.cs) with anInvalidCastException(RoleType[]toList<RoleType>) becauseZ.EntityFramework.Plus.Future()wraps the reader inCreateEntityDataReader, which callsNpgsqlDataReader.GetValue()(returningRoleType[]) and casts directly toT—the same issue noted inEmailOutboxList.cs. Keeping the converter with aValueComparersilencesCoreEventId.CollectionWithoutComparerwithout breaking.Future()batching or changing the database schema/snapshot.How was it tested?
dotnet ef migrations has-pending-model-changes --project Common --startup-project MigrationHelper --context MigrationOpenShockContext.Common.Tests/OpenShockDb/OpenShockContextModelTests.csconfirmingOpenShockContextinitializes without emittingCoreEventId.CollectionWithoutComparerand thatAdminUsersView.Roleshas both aValueConverterandValueComparer.API.IntegrationTests/Tests/AdminUsersViewTests.cs, including HTTP tests againstGET /1/admin/usersexercisingZ.EntityFramework.Plus.Future()/.FutureValue()and DynamicLinq for both empty and populatedRoles.0warnings/errors) and ran the full Release test suite (dotnet test -c Release --solution OpenShockBackend.slnx): all 454 tests passed.Checklist