Skip to content

fix mysql introspection json columns#1495

Closed
aiprojectchiwa wants to merge 1 commit into
prisma:mainfrom
aiprojectchiwa:fix/mysql-introspection-json-string
Closed

fix mysql introspection json columns#1495
aiprojectchiwa wants to merge 1 commit into
prisma:mainfrom
aiprojectchiwa:fix/mysql-introspection-json-string

Conversation

@aiprojectchiwa

Copy link
Copy Markdown

Summary

Fix MySQL/MariaDB introspection in Prisma Studio when the introspection query returns aggregated columns as a JSON string instead of an array.

This prevents Studio from crashing with errors like:

  • a.sort is not a function
  • columns.sort is not a function

Root cause

Some MySQL-compatible backends (notably MariaDB variants) can return the json_arrayagg(...) result as a string payload. The adapter assumed columns was always already an array and called .sort() directly.

Fix

  • Normalize columns before sorting
  • Parse JSON string payloads when needed
  • Keep the existing behavior unchanged for proper array results
  • Add a regression test covering the string-returning case

Verification

Validated on Node 24.13.0 with:

  • pnpm typecheck
  • pnpm exec eslint data/mysql-core/adapter.ts data/mysql-core/introspection-hardening.test.ts
  • pnpm test:data
  • pnpm build
  • pnpm check:exports

@TanNhatCMS

Copy link
Copy Markdown

@sorenbs Why has this serious error remained unresolved for such a long time?
image

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Hi @aiprojectchiwa — thanks for digging into this and for the clean regression test. Since this was opened we root-caused the MariaDB failures further: the introspection SQL itself is invalid on MariaDB (cast(... as json) is a syntax error there, and pre-10.5 lacks json_arrayagg entirely), so string-payload parsing alone can't fully fix #1367/#1511. #1547 addresses it at the SQL level (MariaDB-specific aggregation via flavor detection) and includes transport-agnostic string-payload normalization equivalent to your fix, verified against real MariaDB 10.4 and 10.11. We'll close this PR once #1547 lands — thank you for moving the diagnosis forward; the string-payload observation was a genuinely useful clue.

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Closing as discussed — #1547 has landed on main with the SQL-level MariaDB fix (one row per column, no aggregation) plus transport-agnostic string-payload normalization covering the case you diagnosed. Thanks again @aiprojectchiwa for moving this forward; the string-payload observation genuinely helped pin down the root cause.

@sorenbs sorenbs closed this Jul 18, 2026
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.

3 participants