fix: use mysql binary protocol to avoid a lossy conversion#29285
fix: use mysql binary protocol to avoid a lossy conversion#29285jacek-prisma merged 2 commits intomainfrom
Conversation
WalkthroughNon-transactional operations now use the binary-protocol Changes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/adapter-mariadb/src/mariadb.ts (1)
170-177:⚠️ Potential issue | 🟠 Major
SET TRANSACTION ISOLATION LEVELshould usequery()instead ofexecuteRaw().Line 170 uses
tx.executeRaw()(which callsclient.execute(), the binary protocol), but the class explicitly documents that all transaction operations must useclient.query()to avoid the binary protocol, which does not reliably support transactions in the MariaDB driver. TheBEGINstatement correctly usesquery()on line 177. This inconsistency violates the stated design principle and should be fixed.Proposed fix
if (isolationLevel) { - await tx.executeRaw({ - sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`, - args: [], - argTypes: [], - }) + await tx.conn + .query({ sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}` }) + .catch(this.onError.bind(this)) } // Uses `query` instead of `execute` to avoid the binary protocol. await tx.conn.query({ sql: 'BEGIN' }).catch(this.onError.bind(this))
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
packages/adapter-mariadb/src/mariadb.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/_matrix.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/prisma/_schema.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/tests.ts
size-limit report 📦
|
7fc6470 to 600cc77 Compare There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
packages/adapter-mariadb/src/mariadb.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/_matrix.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/prisma/_schema.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/tests.tspackages/client/tests/functional/tracing/tests.tspackages/client/tests/functional/typed-sql/mysql-scalars-nullable/test.tspackages/client/tests/functional/typed-sql/mysql-scalars/test.ts
packages/client/tests/functional/issues/29160-mysql-precision-loss/prisma/_schema.ts Show resolved Hide resolved
600cc77 to ce0e921 Compare There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/adapter-mariadb/src/mariadb.ts (1)
170-178:⚠️ Potential issue | 🟠 MajorKeep isolation-level setup on
querypath (notexecuteRaw).Line 181 routes
SET TRANSACTION ISOLATION LEVELthroughexecuteRaw(binary protocol), but the class comment explicitly states "All transaction operations useclient.queryinstead ofclient.executeto avoid using the binary protocol, which does not support transactions in the MariaDB driver." All other transaction control statements—BEGIN (line 188), COMMIT (line 95), ROLLBACK (line 108), and SAVEPOINT operations—useclient.query. This inconsistency violates the established pattern and may break transaction support.Proposed fix
if (isolationLevel) { - await tx.executeRaw({ - sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`, - args: [], - argTypes: [], - }) + await tx.conn.query({ + sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`, + }).catch(this.onError.bind(this)) }
♻️ Duplicate comments (2)
packages/client/tests/functional/issues/29160-mysql-precision-loss/prisma/_schema.ts (1)
14-17:⚠️ Potential issue | 🟠 MajorPin the model column to
Decimal(30,0)for regression fidelity.At Line 16, unconstrained
Decimalcan miss the exact failure mode from issue#29160(Decimal(30,0)).Proposed fix
model AssetAccount { assetId ${idForProvider(provider)} - amount Decimal `@default`(0) + amount Decimal `@default`(0) `@db.Decimal`(30, 0) }packages/adapter-mariadb/src/mariadb.ts (1)
94-104:⚠️ Potential issue | 🟠 MajorEnsure cleanup/close always run on COMMIT/ROLLBACK failures.
At Line 94 and Line 102,
onErrorthrows inside.catch(...), socleanupandclient.end()are skipped on failure.Proposed fix
async commit(): Promise<void> { debug(`[js::commit]`) - - await this.client.query({ sql: 'COMMIT' }).catch(this.onError.bind(this)) - this.cleanup?.() - await this.client.end() + try { + await this.client.query({ sql: 'COMMIT' }) + } catch (error) { + this.onError(error) + } finally { + this.cleanup?.() + await this.client.end() + } } async rollback(): Promise<void> { debug(`[js::rollback]`) - - await this.client.query({ sql: 'ROLLBACK' }).catch(this.onError.bind(this)) - this.cleanup?.() - await this.client.end() + try { + await this.client.query({ sql: 'ROLLBACK' }) + } catch (error) { + this.onError(error) + } finally { + this.cleanup?.() + await this.client.end() + } }
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
packages/adapter-mariadb/src/mariadb.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/_matrix.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/prisma/_schema.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/tests.tspackages/client/tests/functional/tracing/tests.tspackages/client/tests/functional/typed-sql/mysql-scalars-nullable/test.tspackages/client/tests/functional/typed-sql/mysql-scalars/test.ts
packages/client/tests/functional/issues/29160-mysql-precision-loss/tests.ts Show resolved Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
packages/adapter-mariadb/src/mariadb.tspackages/client/tests/functional/issues/29160-mysql-precision-loss/prisma/_schema.ts
packages/client/tests/functional/typed-sql/mysql-scalars-nullable/test.ts Show resolved Hide resolved
Fixes: - outdated snapshots missing `stripped_partial_indexes` - missing `mariadb-mysql.js.wasm` for some MySQL tests that caused them not to be run - corrects some mysql tests to account for minor change in float precision behavior (see prisma/prisma#29285) /test-all <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Expanded query engine testing to support MariaDB MySQL WASM target compatibility alongside MySQL 8 configurations. * Refactored test validation methodology to use programmatic assertions for improved reliability. * Updated schema describer test expectations to reflect current field handling for index structures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
TML-1899
Fixes #29160
Modifies the mariadb adapter to use the binary protocol whenever possible. This solves some edge cases with serializing large numbers.
Also changed the adapter to use phantom queries, because the driver does not support transactions in its binary protocol, so it has to issue
querycalls directly.Summary by CodeRabbit
Bug Fixes
Tests