fix(models): call setUpdatedAt for all docs in insertMany#39718
fix(models): call setUpdatedAt for all docs in insertMany#39718
Conversation
insertMany() only called setUpdatedAt() when a document already had a valid _id. Documents without _id (the common case) got an _id generated but skipped setUpdatedAt(), leaving them without _updatedAt in the database. This caused API response validation failures for endpoints using $ref schemas that require _updatedAt (e.g. subscriptions.getOne). Align insertMany() with insertOne(), which already calls setUpdatedAt() unconditionally. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: 0000e87 The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (12)📓 Common learnings📚 Learning: 2026-01-17T01:51:47.764ZApplied to files:
📚 Learning: 2026-03-15T14:31:28.969ZApplied to files:
📚 Learning: 2026-03-11T16:46:55.955ZApplied to files:
📚 Learning: 2026-03-15T14:31:23.493ZApplied to files:
📚 Learning: 2026-03-09T21:20:12.687ZApplied to files:
📚 Learning: 2026-03-11T22:04:20.529ZApplied to files:
📚 Learning: 2026-03-11T18:15:53.272ZApplied to files:
📚 Learning: 2026-03-16T22:56:54.500ZApplied to files:
📚 Learning: 2026-03-16T11:57:17.987ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
🔇 Additional comments (1)
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
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. Comment |
|
/jira ARCH-2021 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #39718 +/- ##
===========================================
- Coverage 70.98% 70.97% -0.01%
===========================================
Files 3209 3209
Lines 113896 113896
Branches 20677 20660 -17
===========================================
- Hits 80844 80835 -9
- Misses 30997 31003 +6
- Partials 2055 2058 +3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/models/src/models/BaseRaw.ts">
<violation number="1" location="packages/models/src/models/BaseRaw.ts:277">
P2: This spread order preserves a non-string `_id` instead of replacing it with the generated string ID.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/models/src/models/BaseRaw.ts`:
- Around line 275-279: The guard generating a string ObjectId can be defeated
because the spread puts the original doc after the generated _id; change the
assignment so the generated string _id wins (e.g., place the generated _id after
the spread) in both places where this pattern appears in BaseRaw.ts (the block
that currently calls this.setUpdatedAt(doc) and the similar logic inside
insertOne). Update the object construction so the new _id overrides any existing
non-string _id, keep calling setUpdatedAt(doc) as before, and apply the same fix
in insertOne.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f0bf0f31-5b45-4617-9c88-2926707fb9fd
📒 Files selected for processing (1)
packages/models/src/models/BaseRaw.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: 🔎 Code Check / Code Lint
- GitHub Check: 📦 Meteor Build (coverage)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
packages/models/src/models/BaseRaw.ts
🧠 Learnings (2)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
packages/models/src/models/BaseRaw.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
packages/models/src/models/BaseRaw.ts
Co-authored-by: Diego Sampaio <[email protected]>
Fixes an issue with updatedAt not being set during subscription creation.
…ORE MERGE Cherry-picked to test if the insertMany setUpdatedAt fix resolves subscriptions.getOne validation failures. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Diego Sampaio <[email protected]>
Co-authored-by: Diego Sampaio <[email protected]>
insertMany() only called setUpdatedAt() when a document already had a valid _id. Documents without _id (the common case) got an _id generated but skipped setUpdatedAt(), leaving them without _updatedAt in the database. This caused API response validation failures for endpoints using $ref schemas that require _updatedAt (e.g. subscriptions.getOne).
Align insertMany() with insertOne(), which already calls setUpdatedAt() unconditionally.
Proposed changes (including videos or screenshots)
Issue(s)
Steps to test or reproduce
Further comments
Task: ARCH-2061
Summary by CodeRabbit
Bug Fixes
Chores