Skip to content

docs(errors): document mongoose.model() init-order time bomb in standalone scripts#3795

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
docs/errors-mongoose-init-order
Jun 4, 2026
Merged

docs(errors): document mongoose.model() init-order time bomb in standalone scripts#3795
PierreBrisorgueil merged 1 commit into
masterfrom
docs/errors-mongoose-init-order

Conversation

@PierreBrisorgueil

Copy link
Copy Markdown
Contributor

Summary

  • Appends one entry to ERRORS.md documenting the MissingSchemaError init-order time bomb triggered when a repository uses top-level mongoose.model() and is imported from a standalone script (cron, migration) before loadModels() runs.
  • Captures symptom, root cause (ESM DFS eval order), why tests miss it (jest mock intercepts), and both fix patterns (lazy getter / dynamic import after load).

Closes #3789

Test plan

  • Doc-only change — no code modified, no tests needed.
  • Entry matches existing ERRORS.md one-liner format.

Copilot AI review requested due to automatic review settings June 4, 2026 15:42
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 12 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6ca01c2e-f0b6-4498-97ed-752ff768a34d

📥 Commits

Reviewing files that changed from the base of the PR and between 690e756 and 2670b65.

📒 Files selected for processing (1)
  • ERRORS.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/errors-mongoose-init-order

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new entry to ERRORS.md documenting an ESM init-order pitfall where top-level mongoose.model() lookups in repository modules can crash standalone scripts (crons/migrations) with MissingSchemaError when models haven’t been registered yet.

Changes:

  • Appends a one-line ERRORS.md entry describing the mongoose.model() import-time evaluation hazard in standalone scripts, why tests may miss it, and the two recommended mitigation patterns (lazy model getter or dynamic import after loadModels()).

@PierreBrisorgueil PierreBrisorgueil merged commit 8360fce into master Jun 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERRORS.md: document top-level mongoose.model() init-order gotcha

2 participants