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

null check #14172

Merged
merged 1 commit into from
Dec 13, 2023
Merged

null check #14172

merged 1 commit into from
Dec 13, 2023

Conversation

rohanricky
Copy link
Contributor

Summary

null check is missing in $__set method which is causing TypeError: Cannot set properties of null (setting 'isNew')

Repro script

var mongoose = require('mongoose')
console.log(mongoose.version)
let Schema = mongoose.Schema
var eventSchema = new Schema({
  name: { type: String },
  field3: { type: Schema.Types.Mixed },
  __stateBeforeSuspension: {
    field1: { type: String },
    field2: { type: String },
    jsonField: {
        name: { type: String },
        ex: { type: String }
    }
  }
})

eventSchema.add({
  test: { 
    val1: { type: String },
    val2: { type: String }
   }
})

eventSchema.add({
  subSchema4: [{ field1: { type: String } }, { field2: { type: String } }]
})

eventObj.save(function (err, eventObj) {
  var newObject = eventObj.toObject()
  newObject.subSchema4[0] = null
  eventObj.set(newObject)

  eventObj.save(function (err, eventObj1) {

    var newObject2 = eventObj1.toObject()
    newObject2.__stateBeforeSuspension.jsonField.name = 'test4'
    eventObj1.set(newObject2)
  })
})

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

LGTM. Looks like this is a duplicate of #13859, which was fixed by #13883. I'll add a test case from #13883 after merging

@vkarpov15 vkarpov15 added this to the 6.12.4 milestone Dec 13, 2023
@vkarpov15 vkarpov15 merged commit 6d25679 into Automattic:6.x Dec 13, 2023
18 checks passed
vkarpov15 added a commit that referenced this pull request Dec 13, 2023
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.

2 participants