Repository navigation
fix: scope invalidWhereValuesBehavior to high-level abstractions only - #11878
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to e2a7a47
Previous suggestions✅ Suggestions up to commit 29ca732
Suggestions
|
||||||||||||||||||||||||||||||||||
commit: |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the invalidWhereValuesBehavior configuration with undefined: 'throw' was not properly throwing errors in two specific scenarios: (1) nested relation objects with other valid predicates in find options, and (2) string-based where parameters in QueryBuilder methods.
Key changes:
- Added validation logic to throw errors when all nested relation properties are undefined
- Implemented
validateWhereParametershelper method to validate null/undefined values in QueryBuilder string parameters - Applied parameter validation across all QueryBuilder
where/andWhere/orWheremethods
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/query-builder/QueryBuilder.ts | Adds validateWhereParameters helper method to validate null/undefined values in where parameters |
| src/query-builder/SelectQueryBuilder.ts | Adds validation calls in where methods and fixes nested relation undefined value handling in buildWhere |
| src/query-builder/UpdateQueryBuilder.ts | Adds validation calls before setParameters in where/andWhere/orWhere methods |
| src/query-builder/DeleteQueryBuilder.ts | Adds validation calls before setParameters in where/andWhere/orWhere methods |
| src/query-builder/SoftDeleteQueryBuilder.ts | Adds validation calls before setParameters in where/andWhere/orWhere methods |
| test/functional/null-undefined-handling/find-options.test.ts | Adds regression test for nested relation objects with other valid predicates |
| test/functional/null-undefined-handling/query-builders.test.ts | Adds regression tests for undefined and null values in string where parameters |
| docs/docusaurus.config.ts | Adds version dropdown to documentation navbar (unrelated to bug fix) |
| docs/docs/query-runner.md | Adds link to QueryRunner API documentation (unrelated to bug fix) |
Deploying typeorm with
|
| Latest commit: |
dc1064c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://33e87056.typeorm.pages.dev |
| Branch Preview URL: | https://fix-invalid-where-values-beh.typeorm.pages.dev |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨
|
||||||||||||||
gioboa
left a comment
There was a problem hiding this comment.
It looks a good piece of code to me 👏 @naorpeled
|
Seems that we call |
Good point, wdyt about |
PR Code Suggestions ✨
|
||||||||||||||
Code Review by Qodo
1. __proto__ key pollution
|
Code Review by Qodo
1. allAllUndefined variable name
|
Code Review by Qodo
1. Empty relation object adds LEFT JOIN
|
PR Code Suggestions ✨No code suggestions found for the PR. |
…e methods - Rename validateWhereCriteria to normalizeWhereCriteria: now returns normalized criteria with null->IsNull() for sql-null, and strips null/undefined keys for ignore mode - Fix empty relation object adding unnecessary LEFT JOIN in buildWhere - Rename allAllUndefined typo to allUndefined - Add tests for sql-null and ignore modes in EntityManager methods Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Persistent review updated to latest commit b383632 |
1 similar comment
|
Persistent review updated to latest commit b383632 |
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Persistent review updated to latest commit e7debf3 |
1 similar comment
|
Persistent review updated to latest commit e7debf3 |
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Persistent review updated to latest commit 4f5d98c |
1 similar comment
|
Persistent review updated to latest commit 4f5d98c |
|
|
Persistent review updated to latest commit dc1064c |
…aults Co-Authored-By: Claude Opus 4.6 <[email protected]>
QB .where() is a low-level API and should not be affected by invalidWhereValuesBehavior per PR typeorm#11878 scoping changes. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…#11878) Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Giorgio Boa <[email protected]> (cherry picked from commit 46d5b84)
…#11878) Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Giorgio Boa <[email protected]> Co-authored-by: Lucian Mocanu <[email protected]> (cherry picked from commit 46d5b84)
| } | ||
|
|
||
| /** | ||
| * Recursively validates an object where clause, throwing for null/undefined |
There was a problem hiding this comment.
As far as I remember it was due to nested relations
There was a problem hiding this comment.
ah okay, also saw the test, i understand now :) thank you!



Problem
invalidWhereValuesBehaviorwas being applied to QueryBuilder's.where()method, which is a low-level API. This meant that users who setnull: "throw"orundefined: "throw"would get errors even when using QB directly — where they might intentionally be passing dynamic values and handling the SQL themselves.The setting should only guard against accidental null/undefined in high-level APIs like
.find(),repository.update(), andmanager.delete(), where null/undefined silently changes query semantics (e.g.,findBy({ id: undefined })returns the first row).Changes
Core
invalidWhereValuesBehaviorchecks fromQueryBuilder.getWherePredicateCondition()— QB.where()now passes null/undefined through as-is (pre-feature behavior)OrmUtils.validateWhereCriteria()— recursive validation for object-style where criteria, called before QB executionEntityManager.update(),.delete(),.softDelete(),.restore()(object criteria branch)SelectQueryBuilder.buildWhere()— throws on all-undefined nested objects when configuredTests
find-options.test.ts— converted QB.where()calls to.setFindOptions(), added nested relation partial-undefined testquery-builders.test.ts— rewritten to test EntityManager/Repository methods, added tests verifying QB.where()is unaffectedDocs
.where()(generatesWHERE col = NULL, always false)What's affected
invalidWhereValuesBehaviorapplies?repository.find()/findOne()/findBy()manager.update()/delete()/softDelete()/restore()repository.update()/delete()qb.setFindOptions()qb.where()/.andWhere()/.orWhere()