Skip to content

fix: apply default 'throw' behavior in normalizeWhereCriteria when options not set - #12594

Closed
sunchengrong wants to merge 1 commit into
typeorm:masterfrom
sunchengrong:fix-12578-normalize-where-criteria
Closed

sunchengrong wants to merge 1 commit into
typeorm:masterfrom
sunchengrong:fix-12578-normalize-where-criteria

Conversation

@sunchengrong

Copy link
Copy Markdown

Fix #12578 — normalizeWhereCriteria() should default to 'throw' behavior

Problem

When invalidWhereValuesBehavior is not configured in the DataSource options, OrmUtils.normalizeWhereCriteria() immediately returns the criteria without checking for undefined/null values:

if (!options) {
    return criteria  // Bug: skips all validation
}

This contradicts the documented default behavior, which states that 'throw' is the default. As a result, UPDATE queries can silently execute with buggy filters like WHERE col = null without any warning.

Solution

When options is not provided, resolve it to the documented defaults ({ undefined: "throw", null: "throw" }) instead of short-circuiting:

const resolvedOptions: InvalidFindOptionsWhereBehavior = options ?? {
    undefined: "throw",
    null: "throw",
}

All internal references to options are updated to use resolvedOptions.

Impact

  • With invalidWhereValuesBehavior configured: No change — existing behavior is preserved
  • Without invalidWhereValuesBehavior: Now correctly throws on undefined/null values in where conditions, matching the documented default

Files changed

  • src/util/OrmUtils.ts — Resolve options to documented defaults when not provided

…tions not set

Fixes typeorm#12578

When `invalidWhereValuesBehavior` is not configured in the DataSource,
`OrmUtils.normalizeWhereCriteria()` was returning the criteria immediately
without checking for undefined/null values. This contradicts the
documented default behavior ('throw') and allows UPDATE queries to
execute with buggy filters like `WHERE col = null`.

The fix resolves the options parameter to a default of { undefined: 'throw',
null: 'throw' } when not provided, matching the documented behavior.
@github-actions github-actions Bot added linked-issue PR references an issue possible-duplicate PR may duplicate an existing open PR labels Jun 19, 2026
@github-actions

Copy link
Copy Markdown

Other open PRs also reference #12578: #12579. Maintainers may want to coordinate.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. normalizeWhereCriteria extra comments 📘 Rule violation ⚙ Maintainability
Description
Two new inline comments were added explaining the default behavior, which adds comment noise instead
of relying on existing JSDoc or self-documenting code. This conflicts with the guideline to avoid
extra AI-like commentary and keep changes minimal.
Code

src/util/OrmUtils.ts[R665-666]

+        // When options is not provided, use the documented default behavior
+        // (throw on undefined/null) rather than silently passing through
Evidence
PR Compliance ID 4 requires avoiding extra comments/noise. The added inline comments at
src/util/OrmUtils.ts[665-666] introduce new explanatory commentary that can be folded into
existing JSDoc or removed.

Rule 4: Remove AI-generated noise
src/util/OrmUtils.ts[665-666]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The change adds two new inline comments that are potentially redundant and increase comment noise.

## Issue Context
Compliance guidance discourages extra AI-like commentary; prefer concise/self-documenting code or existing JSDoc when explanation is needed.

## Fix Focus Areas
- src/util/OrmUtils.ts[665-666]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Qodo Logo

@naorpeled

Copy link
Copy Markdown
Member

Closing as this is a duplicate of #12579

@naorpeled naorpeled closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compliance violation linked-issue PR references an issue possible-duplicate PR may duplicate an existing open PR

Development

Successfully merging this pull request may close these issues.

OrmUtils.normalizeWhereCriteria() does not implement described default behaviour for invalidWhereValuesBehavior

2 participants