PR #12254 introduced bug: Methods defined in shared schemas get removed
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.5.5
Node.js version
16.6
MongoDB server version
6.0.1
Description
PR https://github.com/Automattic/mongoose/issues/12254 introduces a bug where instance methods defined in shared schema get deleted.
Problem located in line 38 in file mongoose/lib/helpers/model/applyMethods.js
Steps to Reproduce
- Install mongoose 6.5.5
- Run this bug demo script:
const mongoose = require('mongoose')
mongoose.set('debug', true)
const sharedSubSchema = new mongoose.Schema({
name: {
type: String
}
})
sharedSubSchema.methods.sharedSubSchemaMethod = function () {
console.log('sharedSubSchemaMethod called')
}
const mainDocumentSchema = new mongoose.Schema({
subdocuments: {
type: [sharedSubSchema],
required: true
}
})
const MainDocument = mongoose.model('MainDocument', mainDocumentSchema)
const secondaryDocumentSchema = new mongoose.Schema({
subdocuments: {
type: [sharedSubSchema],
required: true
}
})
const SecondaryDocument = mongoose.model('SecondaryDocument', secondaryDocumentSchema)
const mainDoc = new MainDocument({
subdocuments: [
{
name: 'one'
}
]
})
const secondaryDoc = new SecondaryDocument({
subdocuments: [
{
name: 'secondary'
}
]
})
console.log(mainDoc.subdocuments[0].sharedSubSchemaMethod)
console.log(secondaryDoc.subdocuments[0].sharedSubSchemaMethod)
Expected Behavior
Sub-Document method should be defined on both models, not only one.
Buggy output mongoosejs 6.5.5 [Function (anonymous)] undefined
Correct output mongoosejs 6.5.4 [Function (anonymous)] [Function (anonymous)]
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Confluent Platform Component Changelogs | Confluent ...
Common¶. PR-428 - Upgrade Netty ; Kafka¶. PR-11742 - KAFKA-13636: Fix for the group coordinator issue where the offsets are deleted for unstable...
Read more >Recommended update for terraform-provider-aws | SUSE Support
An update that has one recommended fix can now be installed. Description: This update for terraform-provider-aws fixes the following issues:.
Read more >DataStax Enterprise 5.1 release notes | DSE 5.1 Admin guide
Resources can be deleted when authorization is enabled, given the correct permissions. (DSP-20749); Fixed a bug where a decryption block cache occasionally was ......
Read more >September 2021 Galaxy Release (v 21.09) — Galaxy Project 22.05 ...
It is also possible to configure the default Tool Panel View using the domain name of the server, so “flavors” of Galaxy can...
Read more >Changelog - Changes since 3.3.9-RC1 - phpBB
Bug. [PHPBB3-17058] - Special character issue in emails from PHP 8.0 and higher ... [PHPBB3-15594] - The deprecated AOL contact field should be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just stumbled upon the same problem. For reference: The corresponding PR is https://github.com/Automattic/mongoose/pull/12391
Just to clarify: version 6.6.0 also has this bug.