prisma icon indicating copy to clipboard operation
prisma copied to clipboard

fix(adapter-mssql): set VarBinary type when null Bytes? argument is passed #29557

Open AnupamKumar-1 opened this issue 5 months ago β€’ 2 comments

Fixes #29557

When setting a Bytes? (@db.VarBinary(Max)) field to null, the adapter was sending the parameter without a type, causing MSSQL to default to nvarchar and throw an implicit conversion error.

Fixed by explicitly passing sql.VarBinary as the type for null bytes arguments in performIO.

All 87 tests passing locally.

AnupamKumar-1 avatar Jun 09 '26 07:06 AnupamKumar-1

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ddf6cb5f-fda4-497a-8907-1e21c5df53dd

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 6aaef74d7f6af8dfd7c60c7a6e0bbd0f9b08ffa4 and cc624889dc1243cc5092f6e5e6ad3c9ee30097f6.

πŸ“’ Files selected for processing (2)
  • packages/adapter-mssql/src/mssql.test.ts
  • packages/adapter-mssql/src/mssql.ts

Summary by CodeRabbit

  • Bug Fixes

    • Improved parameter binding for null binary/bytes values in the MSSQL adapter, ensuring UPDATE statements that set binary columns to NULL execute correctly.
  • Tests

    • Added an integration-style MSSQL test that verifies null bytes behavior using a real database connection, and automatically skips when the required test database connection string isn’t provided.

Walkthrough

This PR fixes a bug where updating a Bytes? field mapped to @db.VarBinary(Max) with null using the MSSQL adapter throws an implicit type conversion error. The fix modifies the performIO method to explicitly bind null byte arguments as VarBinary instead of allowing default type inference, which was incorrectly treating them as nvarchar. An integration test validates the fix by creating a table with a binary column, inserting data, updating the column to null, and confirming the operation succeeds.

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly and accurately describes the main fix: handling VarBinary type when null Bytes arguments are passed in the MSSQL adapter.
Description check βœ… Passed The description is related to the changeset, explaining the bug fix, root cause, and implementation approach in the MSSQL adapter.
Linked Issues check βœ… Passed The code changes directly address all objectives from issue #29557: fixing null Bytes field updates by explicitly setting VarBinary type in performIO to prevent nvarchar conversion errors.
Out of Scope Changes check βœ… Passed All changes are scoped to the MSSQL adapter and directly related to fixing the null Bytes parameter type issue described in #29557, with no extraneous modifications.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests
✨ Simplify code
  • [ ] Create PR with simplified code

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

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jun 09 '26 07:06 coderabbitai[bot]

@daltino Thanks for the thorough review!

  • Addressed suggestions 5 & 6: cleanup now uses IF OBJECT_ID(...) IS NOT NULL DROP TABLE to make teardown idempotent, and dispose() is executed in a nested finally block so the connection is always released even if cleanup fails.
  • Addressed suggestion 4: added a comment clarifying that the test is intentionally skipped when TEST_MSSQL_URI is not provided and that MSSQL integration tests run separately against a real MSSQL instance.
  • Addressed suggestion 1: added a comment explaining why bytes requires special handling when the value is null (mssql defaults to nvarchar rather than VARBINARY, which causes the implicit conversion error).

Tested locally against a real MSSQL instance running in Docker; all tests pass, including the new integration test (87/87).

Thanks again for the review.

AnupamKumar-1 avatar Jun 17 '26 03:06 AnupamKumar-1