Skip to content

fix: add ValueComparer for AdminUsersView.Roles - #404

Open
MeowLuckly wants to merge 3 commits into
OpenShock:developfrom
MeowLuckly:fix/admin-users-view-roles-comparer
Open

MeowLuckly wants to merge 3 commits into
OpenShock:developfrom
MeowLuckly:fix/admin-users-view-roles-comparer

Conversation

@MeowLuckly

@MeowLuckly MeowLuckly commented Nov 23, 2026 •

Copy link
Copy Markdown

What does this change?

Closes #336

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.

@MeowLuckly
MeowLuckly requested a review from a team as a code owner November 23, 2026 05:55
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 02f30ed4-ab46-4de6-a1ba-8b36b181ba5d
Commits

Reviewing files that changed from the base of the PR and between 3788aee and 2a660b8.

Files selected for processing: 3

  • API.IntegrationTests/Tests/AdminUsersViewTests.cs
  • Common.Tests/OpenShockDb/OpenShockContextModelTests.cs
  • Common/OpenShockDb/OpenShockContext.cs

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · previous review 3788a

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed [#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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf664132-c813-4653-89df-1861ad98835a
Commits

Reviewing files that changed from the base of the PR and between a03b667 and 3788aee.

Files selected for processing: 3

  • API.IntegrationTests/Tests/AdminUsersViewTests.cs
  • Common.Tests/OpenShockDb/OpenShockContextModelTests.cs
  • Common/OpenShockDb/OpenShockContext.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@hhvrc
hhvrc requested a balanced review from Copilot November 25, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

@hhvrc

hhvrc commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

I think we have tried it before but it ends up breaking in a weird way... 🤔

@MeowLuckly MeowLuckly changed the title fix: remove redundant value converter on AdminUsersView.Roles fix: add ValueComparer for AdminUsersView.Roles Nov 27, 2026
@MeowLuckly

Copy link
Copy Markdown
Author

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:

  1. 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()).
  2. Add HTTP integration tests for GET /1/admin/users covering the full .Future() + DynamicLinq path for empty and populated Roles.
  3. 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!

@hhvrc

hhvrc commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

At this point idk what the value of this pr is anymore 🤔

This branch has not been deployed

No deployments
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.

EF Core spam: AdminUsersView.Roles value converter has no value comparer

3 participants