fix(adapter-mssql): set VarBinary type when null Bytes? argument is passed #29557
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.
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.tspackages/adapter-mssql/src/mssql.ts
Summary by CodeRabbit
-
Bug Fixes
- Improved parameter binding for
nullbinary/bytes values in the MSSQL adapter, ensuring UPDATE statements that set binary columns toNULLexecute correctly.
- Improved parameter binding for
-
Tests
- Added an integration-style MSSQL test that verifies
nullbytes behavior using a real database connection, and automatically skips when the required test database connection string isnβt provided.
- Added an integration-style MSSQL test that verifies
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
@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.