Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from 8.8.2 to 8.8.3 causes "Uncaught TypeError: Invalid path. Must be either string or array" #15071

Open
2 tasks done
christian-schwaderer opened this issue Dec 3, 2024 · 6 comments
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone

Comments

@christian-schwaderer
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.8.3

Node.js version

20.18.0

MongoDB server version

7

Typescript version (if applicable)

No response

Description

I tried upgrading Mongoose from 8.8.2 to 8.8.3. But when trying to create a document I got this issue:

Uncaught TypeError: Invalid `path`. Must be either string or array
      at Object.exports.get (node_modules/mpath/lib/index.js:59:11)
      at Object.exports.getValue (Role node_modules/mongoose/lib/utils.js:624:16)
      at model.Document.$__getValue (Role node_modules/mongoose/lib/document.js:1771:16)
      at getSubdocs (Role node_modules/mongoose/lib/document.js:3695:23)
      at model.Document.$getAllSubdocs (Role node_modules/mongoose/lib/document.js:3723:3)
      at _getPathsToValidate (Role node_modules/mongoose/lib/document.js:2714:25)
      at model.Document.$__validate (Role node_modules/mongoose/lib/document.js:2980:25)
      at node_modules/kareem/index.js:497:25
      at processTicksAndRejections (node:internal/process/task_queues:77:11)

Tried to look a little bit and it seems that the problematic line is for (const { path } of doc.$__schema.childSchemas) {
It seems my schema has a paths property but not a path property and hence an undefined value is passed down. But that's where my knowledge ends. Cannot say how come.

Steps to Reproduce

Sorry but I cannot paste hundreds of lines of company code in here. I have no idea where in my schema the problem is.

Expected Behavior

No response

@hansgen
Copy link

hansgen commented Dec 5, 2024

We're experiencing the same issue.

@maximilianschmid
Copy link

Same here

@vkarpov15 vkarpov15 added this to the 8.9.1 milestone Dec 14, 2024
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Dec 14, 2024
@vkarpov15
Copy link
Collaborator

Without a repro script there's no way for us to guarantee a fix, but in #15098 we added some logic to improve this error message and a potential (but unlikely) fix. Can anyone in this thread please provide a script that demonstrates this issue or some sample code that can give us some hints?

@vkarpov15 vkarpov15 modified the milestones: 8.9.1, 8.9.2 Dec 16, 2024
vkarpov15 added a commit that referenced this issue Dec 16, 2024
fix(document+schema): add potential fix for #15071
@vkarpov15 vkarpov15 added needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Dec 17, 2024
@vkarpov15 vkarpov15 removed this from the 8.9.2 milestone Dec 17, 2024
@christian-schwaderer
Copy link
Author

christian-schwaderer commented Dec 18, 2024

Boy, that took a few hours ... Here we go https://github.com/christian-schwaderer/mongoose-8-8-3-invalid-path-demo
Just clone and run node index.js

Edit: The script expects a Mongo instance running on mongodb://127.0.0.1:27017

@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Dec 18, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.9.2, 8.9.3 Dec 18, 2024
@vkarpov15
Copy link
Collaborator

@christian-schwaderer the issue is due to the fact that your foo module uses Mongoose 8.8.3, but your top-level module uses Mongoose 8.5.2. I managed to repro this issue locally with a similar setup.

Is there anything preventing you from upgrading your top-level module to Mongoose 8.8.3? We will see what we can do to fix this particular issue, but it is worth noting that you should keep your Mongoose versions consistent between shared packages, because we don't test that, for example, schemas from Mongoose 8.5 work with models from Mongoose 8.8.

@vkarpov15
Copy link
Collaborator

Still working on a fix, this is a bit tricky because we need to effectively implement two separate $getAllSubdocs(), one for the normal case and one for the "pre 8.8 mongoose Schema, post 8.8 mongoose model" case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Projects
None yet
Development

No branches or pull requests

4 participants