Skip to content

Mongoose 5.7.5 Cannot read property 'split' of undefined #8251

Closed
@d4rth-v4d3r

Description

@d4rth-v4d3r

BUG

{ "name": "TypeError", "message": "Cannot read property 'split' of undefined", "stack": "TypeError: Cannot read property 'split' of undefined\n at SingleNested.Subdocument.isModified (/home/node/app/ne-route-droker-api/node_modules/mongoose/lib/types/subdocument.js:120:51)\n at SingleNested.<anonymous> (/home/node/app/ne-route-droker-api/node_modules/mongoose/lib/schema.js:1113:60)\n at callMiddlewareFunction (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:482:23)\n at SingleNested.next (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:58:7)\n at _next (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:106:10)\n at process.nextTick (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:507:38)\n at process._tickCallback (internal/process/next_tick.js:61:11)" }

My code was working like a charm and I update from 5.7.1 to 5.7.5 and suddenly this error start happening. I did not write any change in my code. I revert to version 5.7.1 and everything works again.

I built a Docker Image over Ubuntu 16.04.

Mongo 4.1
Node 10 LTS
Mongoose version 5.7.5

Activity

Youssefares

Youssefares commented on Oct 16, 2019

@Youssefares

This is happening in my system as well. Has to do with #8223
It occurs when saving any record for me (at least records with a subdocument).

BastienScanu

BastienScanu commented on Oct 17, 2019

@BastienScanu

I got the same problem, upgrading from v5.6.11 to 5.7.5. Every time I try to save a document in one of my collections I get this error, but other collections work just fine. The problematic collection has subdocuments. I fixed my problem by going back to v5.6.11.

saveman71

saveman71 commented on Oct 17, 2019

@saveman71
Contributor

Same here, here is a repro:

'use strict';

const Promise = require('bluebird');
const mongoose = require('mongoose');
mongoose.Promise = Promise;

// DB
let connect = mongoose.connect('mongodb://localhost:27018/test', {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const ActivitySchema = new mongoose.Schema({
  description: {
    type: String,
    required: true,
  },
}, {
  timestamps: true,
  _id: false,
});

const RequestSchema = new mongoose.Schema({
  name: {},
  activity: ActivitySchema,
});

const Request = mongoose.model('Request', RequestSchema);

// Create test data
connect.then(async () => {
  mongoose.connection.db.dropDatabase();

  const request = await Request.create({
    name: 'lol',
    activity: {
      description: 'title',
    },
  });

  request.activity.set({
    description: 'foo',
  })

  // Will fail
  await request.save();

  // Log request
  console.log(request);
});

I initially thought it was due to the timestamp option but it appears this is more general It seems to work if I disable the timestamps option. Please tell me if that's another bug!

Works fine in 5.7.4, makes sense since the code was introduced in 327b47a

added this to the 5.7.6 milestone on Oct 17, 2019
added
needs repro scriptMaybe a bug, but no repro script. The issue reporter should create a script that demos the issue
on Oct 17, 2019
stieg

stieg commented on Oct 18, 2019

@stieg
Contributor

Error for me stems from lib/schema.js:1113 where this.isModified() is called without arguments. However it seems that the isModified function expects 2 arguments: paths & modifiedPaths. Hence the error. Regression seems to have been introduced in 5.7.5 as 5.7.4 works fine

added a commit that references this issue on Oct 18, 2019
added
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.
and removed
needs repro scriptMaybe a bug, but no repro script. The issue reporter should create a script that demos the issue
on Oct 18, 2019
vkarpov15

vkarpov15 commented on Oct 18, 2019

@vkarpov15
Collaborator

Thanks for the repro script and sorry for the trouble, the fix will be in 5.7.6 👍

saveman71

saveman71 commented on Oct 20, 2019

@saveman71
Contributor

Thanks for the quick fix and thanks for being this reactive!

carolinevk8

carolinevk8 commented on Oct 12, 2022

@carolinevk8

I got the same problem. Is it a bug? If not then can you share the solution

saveman71

saveman71 commented on Oct 12, 2022

@saveman71
Contributor

If you're before 5.7.6 then upgrade (the fix is there) otherwise open a new issue!

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stieg@saveman71@vkarpov15@d4rth-v4d3r@BastienScanu

        Issue actions

          Mongoose 5.7.5 Cannot read property 'split' of undefined · Issue #8251 · Automattic/mongoose