You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: fix up generated query with .update() - #11993
This pull request links relevant issues as Fixes #00000
There are new or updated tests validating the change (tests/**.test.ts)
Documentation has been updated to reflect this change (docs/docs/**.md)
PR Type
Bug fix
Description
Fix generated query to use equality operator instead of IN for single primary key updates
Import Equal operator for single-value comparisons
Add JSDoc parameter documentation to multiple methods
Add test case for UUID primary key update behavior
Diagram Walkthrough
flowchart LR
A["whereInIds with single ID"] --> B["Check if single value"]
B --> C["Use Equal operator instead of IN"]
C --> D["Generate correct SQL with ="]
Loading
File Walkthrough
Relevant files
Bug fix
QueryBuilder.ts
Fix single ID update queries and improve documentation
src/query-builder/QueryBuilder.ts
Import Equal operator from find-options
Refactor getWhereInIdsCondition to use Equal operator for single-value conditions instead of wrapping in In
Extract normalized values into variable for cleaner logic
Add JSDoc parameter documentation to 20+ methods for improved code documentation
Why: The suggestion correctly identifies an edge case where an empty ids array would cause the generation of invalid SQL (IN ()), leading to a runtime error. The proposed fix is a standard and robust way to handle this scenario.
Medium
General
Assert operator in WHERE
Refine the test assertion to specifically check for the = operator within the WHERE clause, rather than anywhere in the query, to prevent false positives from the SET clause.
Why: The suggestion correctly points out that the test assertion is too broad and could pass for the wrong reason. By making the assertion specific to the WHERE clause, the test becomes more robust and accurately verifies the intended change.
In getWhereInIdsCondition, add a check to handle empty ids arrays to prevent generating invalid SQL. If the array is empty, return a condition that always evaluates to false.
Why: The suggestion correctly identifies a bug where passing an empty array to whereInIds would generate invalid SQL, leading to runtime errors, and proposes a standard and effective fix.
Medium
✅ Make test assert WHERE equalitySuggestion Impact:The commit partially implemented the suggestion by replacing the weak "not contain IN" check with a regex that matches an IN( pattern. It did not implement the improved WHERE-specific equality assertion or the case-insensitive flags.
Improve the test assertion to specifically check for an = operator within the WHERE clause of the generated query, rather than just its presence anywhere in the query string.
Why: The suggestion correctly points out that the test assertion is too weak and could produce a false positive, proposing a more specific check to ensure the test is robust and validates the intended behavior correctly.
Medium
Fix strict property initialization
Add definite assignment assertions (!) to the id and title properties in the UuidPost entity to prevent TypeScript compilation errors when strictPropertyInitialization is enabled.
Why: The suggestion correctly identifies a potential TypeScript compilation error under strictPropertyInitialization and proposes a standard fix for TypeORM entities, improving code quality and preventing future build issues.
Why: The suggestion correctly identifies an edge case where an empty array of IDs would generate invalid SQL (IN ()), and provides a valid fix to prevent runtime errors.
Medium
Assert equals in WHERE clause
Improve the test assertion to specifically check for an equals sign (=) within the WHERE clause, as the current check could be satisfied by the SET clause.
Why: The suggestion correctly points out that the test assertion is too weak and could pass even if the implementation is incorrect, proposing a more robust check to improve test quality.
Why: The suggestion correctly identifies an edge case where an empty ids array would generate invalid SQL (... IN ()), proposing a robust fix that prevents potential runtime errors.
Medium
General
✅ Strengthen query-shape assertionSuggestion Impact:The test assertion was strengthened by switching from a simple string containment check for "IN" to a regex that specifically matches an IN clause pattern (IN followed by an opening parenthesis), aligning with the suggestion's intent to reduce fragility. The suggested WHERE-clause-only parsing and equality predicate regex were not implemented.
Refine the test assertions to specifically check the WHERE clause for an equality predicate and the absence of IN, making the test more precise and less fragile.
Why: The suggestion improves the test's robustness by making the assertions more specific and less likely to pass or fail for unintended reasons, which enhances test quality.
Add a guard clause to handle empty ids arrays in getWhereInIdsCondition to prevent generating invalid SQL. If the ids array is empty, return a condition that always evaluates to false.
const normalized = (Array.isArray(ids) ? ids : [ids]).map((id) =>
metadata.ensureEntityIdMap(id),
)
++// avoid generating invalid SQL for empty ids (e.g. `IN ()`)+if (normalized.length === 0) {+ return new Brackets((qb) => qb.where("0=1"))+}
// using in(...ids) for single primary key entities
if (!metadata.hasMultiplePrimaryKeys) {
const primaryColumn = metadata.primaryColumns[0]
// getEntityValue will try to transform `In`, it is a bug
// todo: remove this transformer check after #2390 is fixed
// This also fails for embedded & relation, so until that is fixed skip it.
if (
!primaryColumn.transformer &&
!primaryColumn.relationMetadata &&
!primaryColumn.embeddedMetadata
) {
const values = normalized.map((id) =>
primaryColumn.getEntityValue(id, false),
)
return {
[primaryColumn.propertyName]:
values.length === 1 ? Equal(values[0]) : In(values),
}
}
}
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a bug where an empty ids array would lead to invalid SQL (IN ()), causing a runtime error. The proposed fix prevents this crash and improves the method's robustness.
Medium
✅ Assert equality in WHERE clauseSuggestion Impact:The commit updated the "no IN" assertion from a simple substring check to a regex matching an IN clause pattern. It did not implement the suggested refinement to assert "=" specifically within the WHERE clause (nor the case-insensitive flags).
Refine the test assertion to specifically check for an equals sign (=) within the WHERE clause, not just anywhere in the query, to avoid false positives from the SET clause.
Why: The suggestion correctly points out a flaw in the test assertion that could lead to a false positive, as an UPDATE query's SET clause will always contain an = character. Improving the test makes it more reliable.
Why: The suggestion correctly identifies an edge case where an empty ids array could lead to invalid SQL (IN ()), proposing a robust fix that prevents potential runtime errors.
Medium
Fix strict property initialization
Add definite assignment assertions (!) to the id and title properties in the UuidPost entity to prevent potential strictPropertyInitialization errors.
Why: The suggestion correctly identifies a potential TypeScript compilation error under strictPropertyInitialization and provides a valid fix, improving the robustness of the test entity.
Low
General
✅ Assert against the WHERE clauseSuggestion Impact:The test assertion for avoiding IN usage was tightened from a broad string check (`to.not.contain("IN")`) to a regex that specifically matches the `IN (` pattern, aligning with part of the suggestion (though it did not scope assertions to the WHERE clause or refine the "=" check).
Why: The suggestion correctly points out a flaw in the test assertion that could lead to a false positive, and the proposed improvement makes the test more robust and accurate.
Multiple JSDoc blocks add @param tags with no descriptions, which reads as autogenerated comment
noise and adds no value. This conflicts with the requirement to avoid AI-like/low-signal comments
and keep style consistent.
PR Compliance ID 4 prohibits introducing comment noise or AI-like additions. The added JSDoc
@param entries provide only parameter names without any descriptive content, which is low-signal
and repeated across the file.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
New JSDoc `@param` tags were added without any parameter descriptions (only names), creating low-value comment noise.
## Issue Context
The compliance checklist requires avoiding AI-generated/low-signal comments and keeping style consistent.
## Fix Focus Areas
- src/query-builder/QueryBuilder.ts[105-106]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
The new test asserts the generated SQL does not contain the substring "IN", which can be brittle if
future query formatting/keywords or identifiers include "IN" even when the WHERE operator is
correct. This is low risk because the test also validates actual update behavior, but tightening the
assertion would reduce flakiness.
The test uses broad substring matching on the whole SQL string, not specifically the WHERE
clause/operator, making it sensitive to unrelated SQL changes.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The test checks `qb.getQuery()` with `to.not.contain("IN")`, which can become flaky if the SQL text contains the substring `IN` for reasons unrelated to using the `IN` operator in the WHERE clause.
### Issue Context
The intent is to ensure single-id `whereInIds` generates `=` instead of `IN (...)`.
### Fix Focus Areas
- test/functional/repository/update-by-criteria/repository-update-by-criteria.test.ts[197-200]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #11629
Description of change
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)