Skip to content

Conversation

@ghuls
Copy link

@ghuls ghuls commented Jan 22, 2026

Proposed changes (including videos or screenshots)

Fix setImportFileRocketChatAttachment, by first setting "attachements" to [] when it is undefined before trying to add attachments.

Issue(s)

#37058 (comment)

Steps to test or reproduce

Steps to reproduce:

  1. Import Slack archive: users and channels
  2. Fix MongoDB so imported messages show up in channels (otherwise channels look empty) as currently Slack import does not work properly at all. Multiple options:
  3. After importing Slack messages go to Admin->Import and click Downloading pending files

Errors like this will be seen for every file that gets downloaded:

@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)? [2026-01-13T18:31:19.543Z] ERROR (Pending Files Importer/558597 on machine-01): Cannot apply $addToSet to non-array field. Field named 'attachments' has non-array type null
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?     err: {
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "type": "MongoServerError",
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "message": "Cannot apply $addToSet to non-array field. Field named 'attachments' has non-array type null",
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "stack":
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?           MongoServerError: Cannot apply $addToSet to non-array field. Field named 'attachments' has non-array type null
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?               at UpdateManyOperation.execute (/home/ghuls/.meteor/packages/npm-mongo/.6.16.1.1i7rrhnsm1ig++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/src/operations/update.ts:192:32)
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?               at processTicksAndRejections (node:internal/process/task_queues:105:5)
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?               at tryOperation (/home/ghuls/.meteor/packages/npm-mongo/.6.16.1.1i7rrhnsm1ig++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/src/operations/execute_operation.ts:283:14)
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?               at executeOperation (/home/ghuls/.meteor/packages/npm-mongo/.6.16.1.1i7rrhnsm1ig++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/src/operations/execute_operation.ts:115:12)
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?               at Collection.updateMany (/home/ghuls/.meteor/packages/npm-mongo/.6.16.1.1i7rrhnsm1ig++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/src/collection.ts:420:12)
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?               at IncomingMessage.<anonymous> (app/importer-pending-files/server/PendingFileImporter.ts:145:9)
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "errorLabelSet": {},
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "errorResponse": {
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?         "index": 0,
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?         "code": 2,
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?         "errmsg": "Cannot apply $addToSet to non-array field. Field named 'attachments' has non-array type null"
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       },
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "index": 0,
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?       "code": 2
@rocket.chat/meteor:dsv: I20260113-19:31:19.788(1)?     }

Summary by CodeRabbit

  • Bug Fixes
    • Ensures imported file attachments are properly initialized before being added, preventing missing or misprocessed attachments during import.
    • Makes import attachment updates more reliable by enforcing a two-step initialization and update sequence.

✏️ Tip: You can customize this high-level summary in your review settings.

@ghuls ghuls requested a review from a team as a code owner January 22, 2026 09:26
@changeset-bot
Copy link

changeset-bot bot commented Jan 22, 2026

⚠️ No Changeset found

Latest commit: d6d24e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 22, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Walkthrough

setImportFileRocketChatAttachment in Messages.ts now performs two sequential database updates: first initializes attachments to an empty array where it's not an array, then sets rocketChatUrl/downloaded and adds the attachment.

Changes

Cohort / File(s) Summary
Database Update Refactoring
packages/models/src/models/Messages.ts
Replaced one atomic update with two sequential updateMany operations: (1) ensure attachments is an array (initialize to []), (2) set rocketChat URL and downloaded flag and $addToSet the attachment

Sequence Diagram(s)

(omitted — change involves only application and database interactions)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • MartinSchoeler

Poem

🐰 Two updates, two gentle hops I make,
First I clear the path, then records wake,
Arrays aligned where chaos lay,
A tidy trail for files today,
Hooray — the attachments find their way! 🎉

🚥 Pre-merge checks | ✅ 3
✅ 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: Importing of Slack files' directly describes the main change—fixing Slack file importing by handling the attachments field initialization in the setImportFileRocketChatAttachment function to prevent MongoDB errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • I20260113-19: Request failed with status code 404

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/models/src/models/Messages.ts`:
- Around line 739-751: The first updateMany currently uses { ...query,
attachments: undefined } which won't match documents where attachments is null;
change that filter to explicitly match missing or null attachments, e.g. replace
the first argument of updateMany (the { ...query, attachments: undefined }
object) with { ...query, $or: [ { attachments: { $exists: false } }, {
attachments: null } ] } so those docs get reset to [] before the subsequent
updateMany that $addToSet the attachment.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@ghuls ghuls force-pushed the fix/slack-import-files branch from acfab24 to d6d24e2 Compare January 22, 2026 14:31
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.

1 participant