Skip to content

fix: add async to the method using setFindOptions() - #10787

Merged
naorpeled merged 4 commits into
typeorm:masterfrom
bindon:master
Dec 6, 2025
Merged

naorpeled merged 4 commits into
typeorm:masterfrom
bindon:master

Conversation

@bindon

@bindon bindon commented Mar 22, 2024 •

Copy link
Copy Markdown
Contributor

Description of change

  • Although the return type in TypeScript is Promise<>, it is not possible to catch as shown below (not promise return)
  • This is because 5 modified methods are set to sync.
// definition: Repository<IamOrganization>.exists(options?: FindManyOptions<IamOrganization> | undefined): Promise<boolean>
// expected error: Promise.reject(EntityPropertyNotFoundError)

// AS-IS(not working)
this.repository.exists({ select: 'not_exists' }).catch((error) => console.error);

// AS-IS(working)
try {
  this.repository.exists({ select: 'not_exists' });
} catch (error) {
  console.error(error);
}

// TO-BE(working)
this.repository.exists({ select: 'not_exists' }).catch((error) => console.error);
// or
try {
  await this.repository.exists({ select: 'not_exists' });
} catch (error) {
  console.error(error);
}

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000 - N/A
  • There are new or updated unit tests validating the change - N/A
  • Documentation has been updated to reflect this change - N/A
  • The new commits follow conventions explained in CONTRIBUTING.md

Summary by CodeRabbit

  • Refactor
    • Standardized several entity management methods to explicit async functions while preserving existing Promise-based behavior.
    • Improves consistency and readability when using await across existence checks, counting, and find-and-count operations.
    • No behavioral changes; error handling and results are unchanged.
    • Backward compatible: existing code using Promises or await continues to work without modifications.

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bindon
it looks great to me, I added this PR to our release board.
Kudos for your first PR in this project. 👏

@gioboa gioboa added the size-xs label Jan 24, 2025
@coderabbitai

coderabbitai Bot commented Sep 21, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

EntityManager methods exists, count, countBy, findAndCount, and findAndCountBy were updated to explicitly use the async keyword in their declarations. Return types and internal logic remain unchanged; these methods still return Promises with the same types.

Changes

Cohort / File(s) Summary
EntityManager async keyword additions
src/entity-manager/EntityManager.ts
Added async to method signatures: exists, count, countBy, findAndCount, findAndCountBy. No changes to return types or internal logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Hop, tap-tap, I tweak with care,
Five small asyncs in the air.
Promises still keep their pace,
Same return, a clearer face.
Carrot commits, concise and neat—
Ship the change; it’s light and sweet. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: add async to the method using setFindOptions()" communicates the core intent—adding async where setFindOptions is used—and aligns with the PR changes to EntityManager methods (exists, count, countBy, findAndCount, findAndCountBy). It is somewhat imprecise because it says "the method" singular while the changes affect multiple methods and does not name them. Overall the title is related and informative enough for a quick scan but could be clearer about scope.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@gioboa
gioboa requested review from naorpeled and sgarner September 21, 2025 13:36
@pkg-pr-new

pkg-pr-new Bot commented Sep 21, 2025 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@10787
    

commit: 2497563

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/entity-manager/EntityManager.ts (2)

1162-1173: findAndCountBy async is correct; parity maintained

No further changes needed here.

If not already covered, add a small test asserting that an invalid options shape causes a rejected Promise (caught by .catch/await) for each of these methods. I can help sketch such tests using a stubbed query builder if desired.


974-986: Async verified — approve; add CHANGELOG note

The targeted methods in src/entity-manager/EntityManager.ts are async: exists, count, countBy, findAndCount, findAndCountBy (lines 974, 1005, 1023, 1143, 1162). Synchronous errors from setFindOptions(...) will now surface as Promise rejections; callers must use await + try/catch or .catch(...). Add a brief entry to docs/CHANGELOG stating that synchronous try/catch without await will no longer catch these errors.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4f7b44 and 9e4320a.

📒 Files selected for processing (1)
  • src/entity-manager/EntityManager.ts (5 hunks)
🔇 Additional comments (3)
src/entity-manager/EntityManager.ts (3)

1005-1017: Consistent async return semantics for count

Same rationale as exists; change is correct and low-risk.


1023-1031: countBy async-ification looks good

Brings behavior in line with runtime; keep as-is.


1143-1155: findAndCount now properly rejects via Promise

Good fix; matches find/findBy which were already async.

@coveralls

coveralls commented Sep 21, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 80.773%. first build
when pulling 2497563 on bindon:master
into a46eb0a on typeorm:master.

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

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

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

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@naorpeled
naorpeled merged commit cc07c90 into typeorm:master Dec 6, 2025
@github-project-automation github-project-automation Bot moved this from Proposed to Done in TypeORM Roadmap Dec 6, 2025

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this PR is old, thank you for your help @bindon

mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants