Skip to content

fix(db): pin explicit collation in virtual_collections view for MariaDB 11.6+#3759

Merged
gantoine merged 1 commit into
rommapp:masterfrom
kthistlewood:fix/virtual-collections-collation-mariadb-11.6
Jul 16, 2026
Merged

fix(db): pin explicit collation in virtual_collections view for MariaDB 11.6+#3759
gantoine merged 1 commit into
rommapp:masterfrom
kthistlewood:fix/virtual-collections-collation-mariadb-11.6

Conversation

@kthistlewood

Copy link
Copy Markdown
Contributor

Description
Fixes #3758. On MariaDB 11.6+ the default character_set_collations maps utf8mb4 expressions to uca1400_ai_ci, which clashes with the virtual_collections view's general_ci string literals and JSON_TABLE columns: every /api/collections/virtual request fails with Illegal mix of collations ... for operation '=' and virtual collections disappear from the UI.

This adds migration 0096_fix_virtual_collections (following 0095's recreate-the-view pattern) that recreates the MariaDB view with an explicit COLLATE utf8mb4_general_ci on each string output column (5 collection names, 5 type literals, 1 description). An explicit collation has the strongest coercibility, so comparisons resolve deterministically regardless of the server's character_set_collations setting. The PostgreSQL branch is a no-op (unaffected); downgrade restores the 0095 view verbatim. I pinned utf8mb4_general_ci as the historical default - happy to switch if you'd prefer a different collation.

Tested on the affected instance from #3758 (RomM 5.0.0, external MariaDB 11.8.8, 3,158-rom library migrated from 4.9.2): applied this migration's exact SQL, then queried the view in fresh sessions under both the failing default (utf8mb4=utf8mb4_uca1400_ai_ci) and the legacy mapping (utf8mb4=utf8mb4_general_ci) - all 1,130 virtual collections return correctly in both, and the API returns 200 for every type.

First contribution - happy to rework this to your conventions.

AI disclosure per CONTRIBUTING.md: this fix was diagnosed, authored, and tested by an AI (Claude) operating my homelab, with my review. The SQL was generated programmatically from 0095's source (to avoid transcription drift) with the collation pins added, then validated live against the failing environment. PR responses may also be AI-drafted with my review.

Checklist

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR (not permitted as an outside contributor)
  • I've added unit tests that cover the changes (migration-only change; exercised by the migrations CI workflow, consistent with existing migrations)

Screenshots (if applicable)

n/a - API-level fix; traceback and repro steps in #3758

…DB 11.6+

On MariaDB 11.6+ the default character_set_collations maps utf8mb4
expressions to uca1400_ai_ci, which clashes with the view's general_ci
string literals and JSON_TABLE columns: every /api/collections/virtual
request fails with 'Illegal mix of collations ... for operation ='.

Recreate the view (new migration, 0095 pattern) with an explicit
COLLATE utf8mb4_general_ci on each string output column so comparisons
resolve deterministically regardless of server collation defaults.
PostgreSQL is unaffected (no-op).

Fixes rommapp#3758

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes the virtual collections view use a stable collation on MariaDB and MySQL. The main changes are:

  • Adds Alembic migration 0096_fix_virtual_collections.
  • Pins textual view outputs to utf8mb4_general_ci.
  • Leaves the PostgreSQL view unchanged.
  • Restores the previous non-PostgreSQL view on downgrade.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The migration revision and imports match existing conventions.
  • The downgrade restores the preceding non-PostgreSQL view definition.

Important Files Changed

Filename Overview
backend/alembic/versions/0096_fix_virtual_collections.py Recreates the MariaDB/MySQL virtual collections view with explicit string collations and restores the prior definition on downgrade.

Reviews (1): Last reviewed commit: "fix(db): pin explicit collation in virtu..." | Re-trigger Greptile

@gantoine
gantoine merged commit 92e4074 into rommapp:master Jul 16, 2026
8 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.

[Bug] 5.0.0: virtual collections return HTTP 500 on MariaDB 11.6+ (Illegal mix of collations in virtual_collections view)

2 participants